Nested classes

jrvbdeveloper

Member
Joined
Jul 15, 2007
Messages
17
Programming Experience
Beginner
Hi,

I have a class inside a class. I need to expose the properties of the 2nd class to other classes, therefore it is public. However, I do not wish other classes to be able to create instances of this 2nd class, it should only be instantitated from its parent class. I thought I could resolve this issue by making the constructor of the 2nd class private, but this even prevents the parent class from instantiating its child class! How can I work around this, do I have to make the constructor public and allow anybody to create an instance of the class?

Thanks in advance!
 
Have a look at access modifiers, especially Protected.
 
Have a look at access modifiers, especially Protected.

I'm not sure I understand. If I declare the constructor as Protected, it can't be accessed by the parent class. I'm not using inheritance, rather I have Class2 inside Class1 and I'd like only Class1 to be able to create objects of Class2.

Thanks again.
 
Yeah, I meant Friend. That means only the people writing the assembly can create instances of it.
 
Back
Top