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

Is a string literal?

521


What is methods and methodology?

529


What are streams?

629


Can we use switch statement with strings?

617


Is map ordered in java?

529






What is garbage collection? What is the process that is responsible for doing that in java?

651


What is quick sort in java?

553


What is lifetime variable?

521


Describe 2 different ways to concatenate two strings.

675


Is ++ operator is thread safe in java?

515


What are the properties of thread?

500


What is serial version uid and its importance in java?

594


What is a parameter example?

522


Can substring create new object?

556


What are the advantages of java inner classes?

556