Chapter – 6. INHERITANCE

DELHI 2008

2.d. Answer the questions (i) to(iv) based on the following code :

class Dolls
{
char Dcode[5];
protected: float Price;
void CalcPrice(float);
public: Dolls();
void DInput();
void DShow();
};
class SoftDolls:public Dolls
{
char SDName[20];
float Weight;
public: SoftDolls();
void SDInput();
void DShow();
};
class ElectronicDolls:
public Dolls
{
char EDName[20];
char BatteryType[10];
int Batteries;
public: ElecronicDolls();
void EDInput();
void EDShow();
};

(i) Which type of Inheritance is shown in the above example?

Ans: Hierarchical Inheritance. Since the sub classes are derived from a single base class(Dolls).

(ii) How many bytes will be required by an object of the class ElectronicDolls ?

Ans: 41 Bytes (Explonation: The memory will be reserved as follows: char Dcode[5]; //5 Bytes float Price; //4 Bytes char EDName[20]; //20 Bytes char BatteryType[10]; //10 Bytes int Batteries; //2 Bytes Total = 41 Bytes )

(iii) Write name of all data members accessible from member function of the class SoftDolls.

Ans: Dolls::Price, SoftDolls:: SDName, SoftDolls::Weight

(iv) Write name of member functions accessible an object of the class ElectronicDolls?

Ans: ElectronicDolls::EDInput( ),
ElectronicDolls:: EDShow( ),
Dolls::DInput( ),
Dolls::DShow( )