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 are the advantages and disadvantages of reference counting in garbage collection?

668


Is java 1.7 the same as java 7?

649


Differentiate between overriding and overloading cases?

678


What is charat java?

616


Using callable statement how can you pass out parameters, explain with example?

703






Difference between Preemptive scheduling vs. Time slicing?

657


What are the differences between abstract class and interface?

601


State the significance of public, private, protected class?

740


Explain purpose of sleep() method in java?

714


What is OOP's Terms with explanation?

707


Difference between linkedlist and arraylist.

701


What are the wrapped, classes?

688


Can you pass functions in java?

675


What does it mean that strings are immutable?

695


Does string isempty check for null?

672