Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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?

Answers were Sorted based on User's Feedback



Every class extends object but why it is not possible for every object to invoke clone() method. i..

Answer / 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

Every class extends object but why it is not possible for every object to invoke clone() method. i..

Answer / surendrababu koppula

clone() method must be called on only cloneable objects so sub class must implement Cloneable marker interface

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is application system?

0 Answers  


Can we declare a static variable inside a method?

0 Answers  


Default layout of panel and frame?

3 Answers  


what is associative array

1 Answers   Tech Mentro,


How many types of literals are there in JAVA?

0 Answers   Cap Gemini,


Suppose i have two threads t1 and t2 are running.How the main thread will know that the two threads t1,t2 execution has completed?

2 Answers   Subex,


Can we change the value of static variable?

0 Answers  


How to implement a multithreaded applet?

0 Answers  


what is the difference between a threads start() and run() methods? : Java thread

0 Answers  


What is a treeset in java?

0 Answers  


How do you reverse sort a list in java?

0 Answers  


what is d difference between deep cloning and shallow cloning in core java?

3 Answers   Satyam,


Categories