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 casting in java programming?

768


What is nextint java?

740


Can you declare a private method as static?

905


How many types of variables are there?

882


Can finally block be used without a catch?

729


What are the advantages of packages in java?

900


Why should I use abstract class?

768


What is the use of http-tunneling in rmi?

783


Is jdk required on each machine to run a java program?

1002


What is null statement?

764


Can a static block throw exception?

847


Can we have multiple classes in a single file?

718


What is pojo class in java?

720


what is daemon thread and which method is used to create the daemon thread? : Java thread

734


which is advanced deep technology in java launched by the sun microsystem??? The answer is very logical If u need correct answer mail me at priya_gupta@gmail.com

3421