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

what is abstract class in Java?

652


What is difference between adapter class and listener?

501


Do you know how to reverse string in java?

584


Can Exception handling we can handle multiple catch blocks?

644


Why are the methods of the math class static?

580






Explain about java sdk?

579


Can we sort hashmap in java?

531


What if constructor is protected in java?

559


What are scalar data types?

526


How variables are declared?

517


What are class members by default?

660


How hashmap increases its size in java?

492


Is hashset ordered java?

590


What is the difference between Array and Hash Table?

545


What is javac used for?

514