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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..

1826


What is command line argument

714


What string is utf8?

551


What will happen if a thrown exception is not handled?

566


Explain purpose of sleep() method in java?

623






What does sizeof return?

563


What is constructor and its types?

541


What is the console in java?

680


What is the equal sign?

567


What is prime number in java?

539


What access modifiers can be used for variables?

589


Why collection doesn’t extend cloneable and serializable interfaces?

650


How many days will it take to learn java?

521


What is byte data type?

552


Explain serialization and deserialization in java?

558