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
What is casting in java programming?
What is nextint java?
Can you declare a private method as static?
How many types of variables are there?
Can finally block be used without a catch?
What are the advantages of packages in java?
Why should I use abstract class?
What is the use of http-tunneling in rmi?
Is jdk required on each machine to run a java program?
What is null statement?
Can a static block throw exception?
Can we have multiple classes in a single file?
What is pojo class in java?
what is daemon thread and which method is used to create the daemon thread? : Java thread
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