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

Can we create object of inner class in java?

0 Answers  


Does it matter in what order catch statements for filenotfoundexception and ioexception are written?

0 Answers  


What is the purpose of extern variable?

0 Answers  


What are the 2 types of java programs?

0 Answers  


How much ram can a 64 bit processor theoretically?

0 Answers  


Can we have return statement in finally clause? What will happen?

0 Answers  


What is static binding and where it occurs?

4 Answers  


What is the abstract class?

0 Answers  


why java does compile time polymorphism at run time ?

6 Answers   CTS, TCS,


extending thread class or implementing runnable interface. Which is better? : Java thread

0 Answers  


Explain the polymorphism principle?

0 Answers  


Is it possible to override private or static method in java?

0 Answers  


Categories