I had a question in one of my interview:
Let's say I have a classA and I should create object of classA in only classA not in any other class, for example:
classA{
// some instructions
ClassA a = new ClassA();
}
ClassB{
//Some instructions
ClassA a1 = new ClassA(); // Here I should throw a compilation or runtime error.
}
I told by adding private constructor, but he told that we should have a capability of creating more than once object with in the same class. Can I make this?