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 |
Mention the default values of all the elements of an array defined as an instance variable.
Explain about wait() method?
What is jdbc api?
How will you call an Applet using Java Script Function?
Can we overload final method in java?
what is daemon thread and which method is used to create the daemon thread? : Java thread
How many inner classes can a class have?
What is lossy conversion in java?
what is mean by thread lock?
How do you override a variable in java?
Is it possible to compare various strings with the help of == operator?
Is null false in java?