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 |
After compilation of java program we'll get .class code. If it's generated in OS Windows XP will it work on OS Linux? If yes why? If no why?
What is an class?
What is mvc in java?
Is int primitive data type?
Can an interface extend another interface?
What is the difference between && and & in java?
Can two objects have same hashcode?
What is an anonymous class?
in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
How are multiple inheritances done in Java?
Why do we need to override equals() and hascode() method of object class?
What is xslt in java?