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
Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..
What is command line argument
What string is utf8?
What will happen if a thrown exception is not handled?
Explain purpose of sleep() method in java?
What does sizeof return?
What is constructor and its types?
What is the console in java?
What is the equal sign?
What is prime number in java?
What access modifiers can be used for variables?
Why collection doesn’t extend cloneable and serializable interfaces?
How many days will it take to learn java?
What is byte data type?
Explain serialization and deserialization in java?