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?
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 |
What is the difference between add() and addElement() method in Vector Class ?
What is break and continue statement?
what is the Use of throws exception?
what is meant by encapsulation?
What is an accessor?
Is hashset ordered?
What is the difference between a choice and a list?
How can we make copy of a java object?
Why java uses the concept of the string literal?
Describe what happens when an object is created in java ?
What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?
Which of the classes will have more memory allocated?