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 do you mean by constructor?
What is a string token?
Why is java called java?
What does s mean in regex?
can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread
What is parameters example?
What is concurrent hashmap and its features?
What is a boolean used for?
What is the function of character?
What is the difference between dom and sax parser in java?
What does the “final” keyword mean in front of a variable? A method? A class?
What state is a thread in when it is executing?
what is a working thread? : Java thread
Explain the use of shift operator in java. Can you give some examples?
What is double word?