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 ternary operator? Give an example.
What all access modifiers are allowed for top class ?
explain copyonwritearraylist and when do we use copyonwritearraylist?
How many unicode characters are there?
what is the difference between String s="hello"; and String s=new String("hello");?
What is the difference between actual and formal parameters?
What are the OOPS concepts in Java ?
What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?
How to connect to a remote database using Applet?
What do negative exponents mean?
How to solve the problem of generating the unique hash keys with hash function?
What is actual difference between statement,prepared statement and callable statement and when we have to use it? pls post a answer with code and clear explanation. thanks