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
Can we override constructors?
What is the purpose of format function?
Write a code to create a trigger to call a stored procedure
Objects or references which of them gets garbage collected?
Can singleton class be cloned?
Tell me are there implementations for sorting and searching in the java libarary?
Can a class be private in java?
What is difference between ++ I and I ++ in java?
What is the this keyword?
how to know the total memory occupied by the objects in the ArrayList(Array list may contain duplicate objects)
Why heap memory is called heap?
What are java threads?
What are design patterns and please explain?
What is a line separator in java?
What is the use of inner class?