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
Is a string literal?
What is methods and methodology?
What are streams?
Can we use switch statement with strings?
Is map ordered in java?
What is garbage collection? What is the process that is responsible for doing that in java?
What is quick sort in java?
What is lifetime variable?
Describe 2 different ways to concatenate two strings.
Is ++ operator is thread safe in java?
What are the properties of thread?
What is serial version uid and its importance in java?
What is a parameter example?
Can substring create new object?
What are the advantages of java inner classes?