Chapter – 6. INHERITANCE

OUT SIDE DELHI 2007

2. a. Differentiate between Protected and Private members of a class in context of inheritance using C++. 2

Ans: Protected members will be inherited into the derived class (they are accessible from the derived class). But Private members cannot be accessed from the derived class. (Remember that the memory will be reserved for private as well as protected members for the derived class object)

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

class Teacher
{
char TNo[5],Tname[20],Dept[10];
int Workload; protected : float Salary;
void AssignSal(float);
public: Teacher();
void TEntry();
void TDisplay();
};
class Student
{
char Admno[10],SName[20],Stream[10];
protected: int Attendance,Totmarks;
public: Student();
void SEntry();
void SDisplay();
};
class School:public Student,public Teacher
{
char SCode[10],SName[20];
public: School( );
void SchEntry();
void SchDisplay();
};

(i) Which type of inheritance is depicted by above example?

Ans: Multiplel Inheritance.

(ii) Identify the member function(s) that cannot be called directly from the objects of class School from the following TEntry() SDisplay() SchEntry()

Ans: All the above three member function(s) can be called from the objects of class School.

(iii) Write name of all member(s) accessible from member functions of class School.

Ans: Data Members : Teacher::Salary Student::Attendance Student::Totmarks School::SCode School::SName Member Funcions:Teacher::AssignSal( ) Teacher::TEntry( ) Teacher::TDisplay( ) Student::Sentry( ) Student::SDisplay( ) School::SChEntry( ) School::SChDisplay( )

(iv) If class School was derived privately from class Learner and privately from class Trainer, then name the member function(s)that could be accessed through Objects of class School.

Ans: School::SChEntry( )
School::SChDisplay( )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter6_b.php on line 118

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter6_b.php on line 118

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter6_b.php on line 120

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter6_b.php on line 120