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 abstract class in Java?
What is difference between adapter class and listener?
Do you know how to reverse string in java?
Can Exception handling we can handle multiple catch blocks?
Why are the methods of the math class static?
Explain about java sdk?
Can we sort hashmap in java?
What if constructor is protected in java?
What are scalar data types?
How variables are declared?
What are class members by default?
How hashmap increases its size in java?
Is hashset ordered java?
What is the difference between Array and Hash Table?
What is javac used for?