Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Has anybody used nested classes?

Status
Not open for further replies.

josecarlo

Programmer
Aug 22, 2000
30
PE
Can anybody explain me what are nested classes? and what is their purpose? and is there any other "thing" to use instead it? I read about it in a book about COM.
Extra help: A nested class inherits from another class? I'm blind [#-) about this subject

JOSE CARLOS ARAMBURU
josecarloaa@hotmail.com
 
A nested class is a class with in a class. Where you declare the nested class (i.e. Private or Public) determines how you can instantiate the class object. Consider using a nested class if an object is only needed by the class. A simple example would be a Student class with a nested class called CoursesEnrolled. This would allow a student object to create one or multiple CoursesEnrolled objects. And since CoursesEnrolled wouldn't exist if there wasn't a student that enrolled in the class this would be a good candidate for a nested class. Obviously there is more to this subject but this should give a brief idea of how nested classes are used.

HTH,
JC
 
Ok, thanks. But there is a bit more. On the reading, nested classes are considered as an alternative approach to the implementation of COM interfaces instead of using multiple inheritance. In fact, they say that multiple inheritance is not appropiate to do this. And I thought it was!. The reason? I don't know.

JOSE CARLOS ARAMBURU
josecarloaa@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top