views:

81

answers:

2

An abstract base class (ABC) can have data to support the classes that inherit form it. However, given that its not possible to instantiate an object of an ABC how does the compiler handle this data for cases where we have a number of derived class objects that inherit the ABC. Does the data become associated with the derived class object?

A: 

Yes.

A compiler can only accept an inherited type that has been instantiated with derived, substantial class. This is because

public void RunInstantiate()
{
   IAbstract abc;
   abc = new Implement();   
}

abc will always point to a real object (of the type Implement).

Ngu Soon Hui
A: 

If you are talking about static data, then that data will remain assocciated with the base class. There will still only be one instance of that data in memory no matter how many different classes derive from it.

Non-static data will be associated with each instance of that class. If you create 5 instances of that class, there will be 5 instances of that data in memory, each only accessible through its associated instance.

Mongus Pong
So the non-static data declared in the ABC becomes associated with each instance of the derived class?
Wawel100
What do you mean by associated?
Mongus Pong
I guess what I trying to understand is if its not possible to createan instance of an ABC how does the complier handle different instances of the non-static ABC data?
Wawel100