• +91 9971497814
  • info@interviewmaterial.com

Chapter 5- Inheritance Interview Questions Answers

Question 1 :
Answer the questions (i) to (iv) based on the following :

class ITEM
{
int ID;
char IName[20]; 
protected: 
float Qty; 
public:
ITEM();
void Enter(); 
void View();
 };
Class TRADER;
{
int DCode;
Protected:
char Manager[20]; 
public:
TRADER();
void Enter();  
void View();
};
class- SALEPOINT : public ITEM, private TRADER
{
Char Name[20],Location[20]; 
public:
SALEPOINT(); 
void EnterAll(); 
void ViewAll();
};
(i)Which type of Inheritance out of the following is illustrated in the above example ?
 - Single Level Inheritance
 - Multi Level Inheritance
 - Multiple Inheritance
(ii)Write the names of all the data members, which are directly accessible 
from the member functions 
of class SALEPOINT.
(iii)Write the names of all the member functions, 
which are directly accessible by an object of 
class SALEPOINT.
(iv)What will be the order of execution of the constructors, when an object of class 
SALEPOINT is declared ?

Answer 1 :

  1. Multiple Inheritance
  2. Name, Location, Manager, Qty
  3. EnterAll ( ) , VeiwAll ( ) , Enter ( ) ,ViewO
  4. ITEM ( ) , TRADER (), SALEPOINT ()

Question 2 :
Give the following class definition answer the question that is follow :

class University
{
char name[20]; 
protected:
char vc[20]; 
public :
void estd(); 
void inputdata(); 
void outputdata();
 }
class College : protected University 
int regno; 
protected 
char principal() 
public :
int no_of_students; 
void readdata(); 
void dispdata();
 };
class Department : public College 
char name[20]; 
char HOD[20]; 
public:
void fetchdata(int); 
void displaydata();
 }
(i) Name the base class and derived class of college.
(ii) Name the data member(s) that can be accessed from function display data.
(iii) What type of inheritance is depicted in the above class definition ?
(iv)    What will be the size of an object (in bytes) of  class Department ?

Answer 2 :

(i) Base class : University
Derived class : Department
(ii) char name [20], char principal), no_of_students, char vc[20]
(iii) Multilevel Inheritance
(iv)  85 bytes.

Question 3 :
Answer the question (i) to (iv) based on the following :

class Interior
{
int OrderId; 
char Address[20]; 
protected:
float Advance; 
public:
Interior();
void Book(); 
void View();
};
class Painting : public Interior
int WallArea, ColorCode; 
protected:
char Type; 
public:
Painting(); 
void PBook(); 
void PView();
};
class Billing : public Painting
{
float Charges; 
void Calculate(); 
public:
Billing(); 
void Bill();
void BillPrint();
};
(i) Which type of Inheritance of the following is illustrated in the above example ?
— Single Level Inheritance 
— Multi Level Inheritance 
— Multiple Inheritance

Answer 3 :

Mutli Level Inheritance
(ii)    Write the names of all the data members, which are directly accessible from the member functions of class painting.
Wall Area, Color Code, Type, Advance
Note :
•    No marks to be awaarded for any partial or additional answer(s)
(iii)    Write the names of all the member functions, which are directly accessible from an object of class Billing. Bill(), BillPrint(), PBook(), PViewQ, Book(), View()
Note : No marks to be awarded for any partial/ additional answer(s)
• Constructors can be ignored

Question 4 :
Answer the questions (i) to (iv) based on the following code :

class AC
{
char Model[10]; 
char Date_of_purchase[10]; 
char Company[20]; 
public();
AC();
void enter car detail(); 
void show car detail();
};
class Accessories : protected AC
{
protected:
char Stabilizer[30]; 
char AC_cover[20]; 
public: 
float Price;
Accessories();  
void enteraccessoriesdetails();
void showaccessoriesdetails();
};
class Dealer : public Accessories
{
int No_of_dealers; 
char dealers_name[20]; 
int No_of_products; 
public:
Dealer();
void enterdetails(); 
void showdetails();
}; 
(i)How many bytes will be required by an object of class Dealer and class Accessories?
(ii)Which type of inheritance is illustrated in the above c++ code ? Write the base class and 
derived class name of class Accessories.
(iii)Write names of all the members which are accessible from the objects of class Dealer.
(iv)Write names of all the members accessible from member functions of class Dealer.

Answer 4 :

(i) Object of Dealer = 118 bytes and object of Accessories = 98 bytes
(ii) Multilevel Inheritance, Base class = AC,
Derived class = Dealer
(iii) enterdetails(), showdetails(), price, enteraccessoriesdetails(), showaccessoriesdetails()
(iv) No_of_dealers, dealers name, No_of_products, enterdetails(), showdetails(), Stablizer, Ac_cover, price, enteraccessories details(), showaccessoriesdetails(), entercardetail, showcardetail()

Question 5 :
Consider the following class state :

class State
protected:
int tp; //no. of tourist places 
public:
State()
{
tp = 0;
}
void inctp()
{
tp++;
}
int gettp()
{
return tp;
}
};
Write a code in C + + to publically derive another class 'District' 
with the following additional
members derived in the Public visibility mode.
Data Members
distname - char(50)
population - long
Member functions:
dinput() - To enter distname and population. 
doutput() - To display distname and population on screen.

Answer 5 :

class District : public state
{
private:   
char *distname[50];
long population;  
public :
void dinput()
{   
gets(distname); 
cin>>population;
}
void output()
{
puts(disname);
cout>>population ;
}   
}

Question 6 :

Define a class DanceAcademy in C++ with following description :
Private Members :
•    Enrollno of type int
•    Name of type string
•    Style of type string
•    Fee of type float
•    A member function chkfee( ) to assign the value of feevariable according to the style entered by the user according to the criteriaas given below.

Style

Fee

Classical

10000

Western

8000

Freestyle

11000

Public Members
• A function enrollment) to allow users to enter values for Enrollno, Name,Style and call function chkfee( ) to assign value of fee variable according tothe Style entered by the user.
• A function display( ) to allow users to view the details of all the datamembers.

 

Answer 6 :

class Dance Academy
int Enrollno;   
char Name[20];
Char, style[20-]
Float Fee; 
void chkfee()
{
if(strcmpi(Style."Classical")==0) 
Fee=10000;
else if(strcrapi(Style,"Western")==0)
Fee=8000;
else if(strcmpi(Style,"Freestyle")==0)
Fee=11000; 
}
public;
void enrollment()
{
cout<<"Please enter Enrollno,Name,Style";
cin>>Enrollno;
gets(Name);
gets(Style);
chkfee();
}
void display()
{
cout<<"\n Entered Enrollno, Name Style, and Fee is:
"<
}
};

Question 7 :
Consider the following C++ code and answer the questions from (i) to (iv) :

Class Campus
{
long Id; 
char City[20]; 
protected:
char Country[20]; 
public:
Campus(); 
void Register(); 
void Display();
};
class Dept:private Campus
{
long DCode[10]; 
char HOD[20]; 
protected:
double Budget; 
public:
Dept(); 
void Enter(); 
void Show();
};
class Applicant:public Dept
{
long RegNo; 
char Name[20];
public:
Applicant(); 
void Enroll(); 
void View();
};    
(i) Which type of Inheritance is shown in the above example?
(ii) Write the names of those member functions, 
which are directly accessed from the objects of 
class Applicant.
(iii) Write the names of those data members, 
which can be directly accessible from the member 
functions of class Applicant.
(iv) Is it possible to directly call function Display() 
of class University from an object of 
class Dept?
(Answer as Yes or No).

Answer 7 :

(i) Multilevel Inheritance
(ii)  Enroll(), View(), Enter(), Show().
(iii)  RegNo., Name, Budget.
(iv)  No.

Question 8 :
Consider the following and answer the question given below:

class ITEM 
{
char ICode[10]; 
protected:
char IName[20]; 
public:
ITEM();
void Enter():
void Display();
};
class SUPPLIER
{
char SCode [10]; 
protected:
char SName[25]; 
public :
SUPPLIER(); 
void TEnter(); 
void TDisplay();
};
class SHOP: private SUPPLIER, public ITEM 
{
char SHOPADDRESS [15], SEmail [25]; 
public:
SHOP();
void Enter();
void Display();
};
(i)Which type of inheritance is shown in the above example? 
(ii)Write the names of all the member functions accessible from Enter() 
function of class SHOP.
(iii)Write name of all the member functions accessible through an object of class SHOE
(iv)What will be the order of execution for the constructors ITEM(), SUPPLIER() and SHOP(), 
when an object of class SHOP is declared?

Answer 8 :

(i) Multiple inheritance.
(ii) Display (), TEnter(), TDisplay, Enter(), DisplayO.
(iii) Enter(), DisplayO, ITEM.Enter(), Item. Display.
(iv) ITEM(), then SUPPLIER(), then SHOP().

Question 9 :
Consider the following C++ code and answer the questions from (i) to (iv) :

class Personal:
{
int Class, Rno; char Section; protected:
char Name[20];  
public:  
Personal(); 
void Pentry(); 
void Pdisplayf();
};
class Marks:private Personal
{
float M[5]; 
protected:
char Grade[5]; 
public:
Marks();
void Mentry();
void Mdisplay();
};
class Result : public Marks
{
float Total, Agg; 
public:
char FinalGrade,Comments[20]; 
Result();
void Rcalculate(); 
void Rdisplayt();
};    
(i) Which type of inheritance is shown in the above example ?
(ii) Write the names of those data members, 
which can be directly accessed from the objects of 
class result.
(iii) Write the names of those member functions, 
which can be directly accessed from the objects 
of class Result.
(iv) Write the names of those data members, 
which can be directly accessed from the Mentry() function 
of class Marks.

Answer 9 :

Inheritance Type:
Personal    Base class
1. Marks    Sub class of personal
Result    Sub class of Result
Multilevel Inheritance
2. FinalGrade
Comments [20]
3. Rcalculate ( )
Rdisplay ( )
Mentry ( )
Mdisplay ( )
4. M [5], Rno, Class, Section,
Grade [5]

Question 10 :
Consider the following C++ code and answer the questions from (i) to (iv):

class Student 
{
int Class, Rno; 
char Section; 
protected :
 char SName[20]; 
public:
 Student(); 
void Stentry(); 
void StdisplayO;
};
class Score: private Student
{
float Marks[5]; 
protected:
char Grade[5]; 
public:
Score(); 
void Sentry(); 
void Sdisplay();
};
class Report : public Score
{
float Total, Avg; 
public:
char OverallGrade, Remarks[20]; 
Report(); 
void Revaluate(); 
void RPrint();
};
(i) Which type of inheritance is shown in the above example?
(ii) Write the names of those data members, 
which can be directly accessed from the objects of class 
Report.
(iii) Write the names of those member function, 
which can be directly accessed from the objects of 
class Report.
(iv) Write the names of those data members, 
which can be directly accessed from the Sentry( ) 
function of class Score.

Answer 10 :

1. Student
Score
Report
This is multilevel inheritance:
2. Data Members:
Total,
Avg,
OverallGrade,
Remarks [20],
3. Member functions:
Report ( ),
REvaluate ( ),
RPrint ( ),
Score ( ),    .
Sentry ( ),
Sdisplay ( ).
4. Data members
Marks [5], Class, Rno, Section,
Grade [5], SName.


Selected

 

Chapter 5- Inheritance Contributors

krishan

Share your email for latest updates

Name:
Email:

Our partners