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?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / surendrababu koppula
clone() method must be called on only cloneable objects so sub class must implement Cloneable marker interface
| Is This Answer Correct ? | 3 Yes | 0 No |
How can you handle java exceptions?
Which method must be implemented by all threads?
Which class contains a method: cloneable or object?
Name two subclasses of the TextComponent class?
Why spring singleton is not thread safe?
Is linkedlist thread safe in java?
To set the position and size of a component, which methods are used?
What is a private class in java?
What are the supported platforms by java programming language?
Can we have this () and super () together?
How to make a write-only class in java?
Why is string buffer better than string ?