Every class extends object but why it is not possible for
every object to invoke clone() method. ideally protected
methods should be accessible from sub classes. isn't it?
Answer Posted / aslam
Since the method is protected we can access clone method
only within the package or from subclasses outside the
package.
for ex:
class A{
public static void main(String arg[]){
new A().clone();
/* This is legal since class A is a subclass of Object and
we r accessing within the subclass*/
}
}
class B{
public static void main(String arg[]){
new A().clone();
/* Illegal since we r accessing it from outside object */
}
}
| Is This Answer Correct ? | 5 Yes | 1 No |
Post New Answer View All Answers
What is a vector in java?
How can we make a class singleton?
Does list allow duplicates in java?
What is the full name of java?
Explain the pointers in Java?
List the features of java programming language.
What is an exception in java?
What is 16 bits called?
What is the size of an array?
What are thread groups?
What are untrusted applets?
What is a parent class in java?
What is meant by object oriented programming – oop?
Is java pass by value or pass by reference?
What is string subsequence method?