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...


I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?



I want my class to be developed in such a way that no other class (even derived class) can create it..

Answer / Pratap Singh Chauhan

In Java, you can achieve this by making the constructor of your class private and provide a static factory method to create instances. No other class can directly instantiate a private class.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is the difference between add() and addElement() method in Vector Class ?

2 Answers   TCS,


What is break and continue statement?

1 Answers  


what is the Use of throws exception?

2 Answers  


what is meant by encapsulation?

1 Answers   Aspire,


What is an accessor?

2 Answers   BirlaSoft,


Is hashset ordered?

1 Answers  


What is the difference between a choice and a list?

1 Answers  


How can we make copy of a java object?

1 Answers  


Why java uses the concept of the string literal?

1 Answers  


Describe what happens when an object is created in java ?

1 Answers  


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

1 Answers  


Which of the classes will have more memory allocated?

1 Answers  


Categories