tags:

views:

25

answers:

1

Consider, there is a class called SuperClass from which, ClassA, ClassB, ClassC is derived. From each one of those derived Classes, there are further more two classes are derived each called ChildClassAA and ChildClassAB[AB stands for Bth Child class from the Ath Class.Lets not really pull our hair on this nomenclature].

Now, ideally, I want to declare a general type as a private member of another Class say IndependentClass which can be initialized during run time as either of the objects of type ClassAor ClassB or ClassC and even the derived classes like ClassAA or ClassAB.

Is there a possible way to do it?

+3  A: 

If I understand you correctly, since all of these classes are derived (directly or indirectly) from SuperClass, you could just declare the field to be of type SuperClass.

Syntactic
Great thanks...I was looking for this.
Soham