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 are the advantages and disadvantages of reference counting in garbage collection?
Is java 1.7 the same as java 7?
Differentiate between overriding and overloading cases?
What is charat java?
Using callable statement how can you pass out parameters, explain with example?
Difference between Preemptive scheduling vs. Time slicing?
What are the differences between abstract class and interface?
State the significance of public, private, protected class?
Explain purpose of sleep() method in java?
What is OOP's Terms with explanation?
Difference between linkedlist and arraylist.
What are the wrapped, classes?
Can you pass functions in java?
What does it mean that strings are immutable?
Does string isempty check for null?