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 |
Can we create object of inner class in java?
Does it matter in what order catch statements for filenotfoundexception and ioexception are written?
What is the purpose of extern variable?
What are the 2 types of java programs?
How much ram can a 64 bit processor theoretically?
Can we have return statement in finally clause? What will happen?
What is static binding and where it occurs?
What is the abstract class?
why java does compile time polymorphism at run time ?
extending thread class or implementing runnable interface. Which is better? : Java thread
Explain the polymorphism principle?
Is it possible to override private or static method in java?