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 |
What is application system?
Can we declare a static variable inside a method?
Default layout of panel and frame?
what is associative array
How many types of literals are there in JAVA?
Suppose i have two threads t1 and t2 are running.How the main thread will know that the two threads t1,t2 execution has completed?
Can we change the value of static variable?
How to implement a multithreaded applet?
what is the difference between a threads start() and run() methods? : Java thread
What is a treeset in java?
How do you reverse sort a list in java?
what is d difference between deep cloning and shallow cloning in core java?