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 the difference between an if statement and a switch statement?
How do you achieve polymorphism in java?
Can the garbage collection be forced by any means?
What is volatile keyword in java
What are the new features in java 8? Explain
What are the procedures?
What is outofmemoryerror in java?
Which method must be implemented by all threads?
What is the difference between a scrollbar and a scrollpane?
What two classes are used to read data only?
What is the default size of arraylist in java?
Can a singleton class be inherited?
How objects of a class are created if no constructor is defined in the class?
What is ternary operator?
What is :: operator in java?