Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Tamilnadu State Board New Syllabus Samacheer Kalvi 11th Computer Science Guide Pdf Chapter 16 Inheritance Text Book Back Questions and Answers, Notes.

Tamilnadu Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

11th Computer Science Guide Inheritance Text Book Questions and Answers

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Part I

Choose The Correct Answer :

Question 1.
Which of the following is the process of creating new classes from an existing class?
a) Polymorphism
b) Inheritance
c) Encapsulation
d) super class
Answer:
b) Inheritance

Question 2.
Which of the following derives a dass student from the base class school?
a) school: student
b) class student: public school
c) student: public school
d) class school : public student
Answer:
b) class student: public school

Question 3.
The type of ini. stance that reflects the transitive nature is
a) Single Inheritance
b) Multiple Inheritance
c) Multilevel Inheritance
d) Hybrid Inheritance
Answer:
c) Multilevel Inheritance

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 4.
Which visibility mode should be used when you want the features of the base class to be available to the derived class but not to the classes that are derived from the derived dass?
a) Private
b) Public
c) Protected
d) All of these
Answer:
a) Private

Question 5.
Inheritance is process of creating new dass from
a) Base class
b) abstract
c) derived class
d) Function
Answer:
a) Base class

Question 6.
A dass is derived from a class which is a derived class itself, then this is referred to as
a) multiple inheritance
b) multilevel inheritance
c) single inheritance
d) double inheritance
Answer:
b) multilevel inheritance

Question 7.
Which amongst the following is executed in the order of inheritance?
a) Destructor
b) Member function
c) Constructor
d) Object
Answer:
b) Member function

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 8.
Which of the following is true with respect to inheritance?
a) Private members of base class are inherited to the derived class with private
b) Private members of base class are not inherited to the derived class with private accessibility
c) Public members of base class are inherited but not visible to the derived class
d) Protected members of base class are inherited but not visible to the outside class
Answer:
b) Private members of base class are not inherited to the derived class with private accessibility

Question 9.
Based on the following dass dedaration answer the questions (from 9.1 o 9.5 )

class vehicle
{
int wheels;
public:
void input_data(float,float);
void output_data();
protected:
int passenger;
};
class heavy_vehicle : protected vehicle
{
int diesel_petrol;
protected:
int load;
protected:
int load;
public:
void read_data(float,float)
void write_data(); };
class bus: private heavy_vehicle
{
char Ticket[20];
public:
void fetch_data(char);
void display_data(); >;
};

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 9.1.
Which is the base class of the class heavy, vehicle?
a) Bus
b) heavy_vehicle
c) vehicle
d) both (a) and (c)
Answer:
c) vehicle

Question 9.2.
The data member that can be accessed from the function displaydataQ
a) passenger
b) load
c) Ticket
d) All of these
Answer:
d) All of these

Question 9.3.
The member function that can be accessed by an objects of bus Class is
a) input_data()
b) read_data() ,output_data()write_data()
c) fetch_data(),display_data()
d) All of these
Answer:
c) fetch_data(),display_data()

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 9.4.
The member function that is inherited as
public by Class Bus .
a) input_data()
b) read_data(),output_data(),write_data()
c) fetch_data(), display_data()
d) None of these
Answer:
d) None of these

Question 10.
class x
{
int a;
public :
x()
{}
};
class y
{
x x1;
public:
y()
{}
};
class z : public y,x
{
int b;
public:
z()
{}
}z1;

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

What is the order of constructor for object zl to be invoked?
a) z,y,x,x
b) x,y,z,x
c) y,x,x,z
d) x,y,z
e) x,y,x,z
Answer:
e) x,y,x,z

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Part – II

Very Short Answers

Question 1.
What is inheritance?
Answer:
It is a process of creating new classes called derived classes, from the existing or base classes.

Question 2.
What is a base class?
Answer:
The class to be inherited is called base class or parent class.

Question 3.
Why derived class is called power packed class?
Answer:
The derived class is a power packed class, as it can add additional attributes and methods and thus enhance its functionality.

Question 4.
In what multilevel and multiple inheritance differ though both contains many base class?
Answer:
In case of multiple inheritance derived class have more than one base classes (More than one parent). But in multilevel inheritance derived class have only one base class (Only one parent).

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 5.
What is the difference between public and private visibility mode?
Answer:
Private visibility mode:
When a base class is inherited with private visibility mode the public and protected members of the base class become ‘private’ members of the derived class.

Public visibility mode:
When a base class is inherited with public visibility mode, the protected members of the base class will be inherited as protected members of the derived class and the public members of the base class will be inherited as public members of the derived class.

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Part – III

Short Answers

Question 1.
What are the points to be noted while deriving a new class?
Answer:
The following points should be observed for defining the derived class.

  • The keyword class has to be used.
  • The name of the derived class is to be given after the keyword class.
  • A single colon.
  • The type of derivation (the visibility mode), namely private, public or protected. If no visibility mode is specified ,then by default the visibility mode is considered as private.
    The names of all base classes(parent classes) separated by comma.

class derivedclass_name :visibility_mode
base_class_name
{
// members of derived class
};

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 2.
What is difference between the members present in the private visibility mode and the members present in the public visibility mode?
Answer:
Private visibility mode:
When a base class is inherited with private visibility mode the public and protected members of the base class become ‘private’ members of the derived class.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 1
Private visibility members can not be inherited further. So, it can not be directly access by its derived classes.
Public visibility mode:
When a base class is inherited with public visibility mode, the protected members of the base class will be inherited as protected members of the derived class and the public members of the base class will be inherited as public members of the derived class.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 2
Public visibility members can be inherited by its child and can access in it.

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 3.
What is the difference between polymorphism and inheritance though are used for reusability of code?
Answer:
Inheritance:

  • Promotes code sharing and reduces development cost.
  • Inheritance is implemented on classes.
  • Inheritance type may be a single inheritance, multiple inheritance, multilevel inheritance, hierarchical inheritance and hybrid inheritance.

Polymorphism:

  • Reduces the complexity of the program.
  • Polymorphism is a common interface for multiple form.
  • Polymorphism is basically implemented on function.
  • Polymorphism may be a compile^ Time polymorphism (overloading) or run-time polymorphism (overriding).

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 4.
What do you mean by overriding?
Answer:
When a derived class member function has the same name as that of its base class member function ,the derived class member function shadows/hides the base class’s inherited function. This situation is called function overriding and this can be resolved by giving the base class name followed by :: and the member function name.

Question 5.
Write some facts about the execution of constructors and destructors in inheritance.
Answer:
Somefacts about the execution of constructor in inheritance.

  • Base class constructors are executed first, before the derived class constructors execution.
  • Derived class can not inherit the base class constructor but it can call the base class constructor by using.
  • If there are multiple base classes ,then its start executing from the left most base class.
  • In multilevel inheritance, the constructors will be executed in the order of inheritance.

Some facts about the execution of destructor in inheritance.

  • Own (Derived) class constructors are executed first, before the base class destructors execution.
  • Derived class can not inherit the destructor.
  • In multilevel inheritance, the destructors will be executed in the reverse order of inheritance.

IV. Explain In Brief (Five Marks)

Question 1.
Explain the different types of inheritance.
Answer:
Types of Inheritance;
There are different types of inheritance viz., Single Inheritance, Multiple inheritance, Multilevel inheritance, hybrid inheritance and hierarchical inheritance.

1. Single Inheritance:
When a derived class inherits only from one base class, it is known as single inheritance.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 3

2. Multiple Inheritance;
When a derived class inherits from multiple base classes it is known as multiple inheritance.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 4

3. Hierarchical inheritance:
When more than one derived classes are created from & single base class known as Hierarchical inheritance.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 5

4. Multilevel Inheritance
The transitive nature of inheritance is itself reflected by this form of inheritance. When a class is derived from a class which is a derived class – then it is referred to as multilevel inheritance.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 6

5. Hybrid inheritance:
When there is a combination of more than one type of inheritance, it is known as hybrid inheritance. Hence, it may be a combination of Multilevel and Multiple inheritance or Hierarchical and Multilevel inheritance or Hierarchical, Multilevel and Multiple inheritances.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 7

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 2.
Explain the different visibility mode through pictorial representation.
Answer:
Private visibility mode:
When a base class is inherited with private visibility mode the public and protected members of the base class become ‘private’ members of the derived class.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 8

Protected visibility mode:
When a base class is inherited with protected visibility mode the protected and public members of the base class become ‘protected members’ of the derived class.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 9

Public visibility mode:
When a base class is inherited with public visibility mode , the protected members of the base class will be inherited as protected members of the derived class and the public members of the base class will be inherited as public members of the derived class.
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 10

Question 3.
#include
#include
#include
using name spacestd;
class publisher
{
char pname[15];
char hoffice[15];
char address[25];
double turnover;
protected:
char phone[3][10];
void register();
public:
publisher();
publisher();
void enter data();
void disp data();
};
class branch
{
char bcity[15];
char baddress[25];
protected:
int no_of_emp;
public:
char bphone[2][10];
branch();
~branch();
void havedata();
void givedata();
};
class author: public branch, publisher
{
int aut_code;
charaname[20];
float income;
public:
author();
~author();
void getdata();
void putdata();
};

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Answer The Following Questions Based On The Above Given Program:

3.1. Which type of Inheritance is shown in the program?
3.2. Specify the visibility mode of base classes.
3.3 Give the sequence of Constructor/Destructor Invocation when object of class author is created.
3.4. Name the base class(/es) and derived class (/es).
3.5 Give number of bytes to be occupied by the object of the following class:
(a) publisher
(b) branch
(c) author
3.6. Write the names of data members accessible from the object of class author.
3.7. Write the names of all member functions accessible from the object of class author.
3.8 Write the names of all members accessible from member functions of class author.
Answer:
3.1 Multiple Inheritance
3.2 public .
3.3 Constructors branch, publisher and author are executed.
Destructors author, publisher and branch will be executed.
3.4 Base classes : branch and publisher Derived class : author
3.5 a) publisher class object requires 93 bytes
b) branch class object requires 64 bytes
c) author class object requires 181 bytes

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 4.
Consider the following C++ code and answer the questions.
class Personal
{
int Class, Rno;
char Section;
protected:
char Name[20];
public:
personal();
void pentry();
void Pdisplay();
};
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, Commence[20];
Result();
void Rcalculate();
void Rdisplay();
};

4.1. Which type of Inheritance is shown in the program?
4.2. Specify the visibility mode of base classes.
4.3 Give the sequence of Constructor/Destructor Invocation when object of class Result is created.
4.4. Name the base class(/es) and derived class (/es).
4.5 Give number of bytes to be occupied by the object of the following class:
(a) Personal
(b) Marks
(c) Result
4.6. Write the names of data members accessible from die object of class Result.
4.7. Write the names of all member functions accessible from the object of class Result.
4.8 Write the names of all members accessible from member functions of class Result.
Answer:
4.1 Multilevel Inheritance
4.2 For Marks class – private visibility
For Result class – public visibility
4.3 Constructors Personal, Marks and Result be executed.
Destructors Result, Marks and Personal will be executed.
4.4 Base classes : Personal and Marks Derived classes : Marks and Result

4.5 a) Personal class object requires 28 bytes (using Dev C++)
b) Marks class object requires 53 bytes (using Dev C++)
c) Result class requires 82 bytes (using Dev C++)

4.6 Data members FinalGrade, Commence(Own class members) alone can be accessed.
No members inherited under public, so base class members can not be accessed.

4.7 Member functions
Rcalculate( ), Rdisplay (own class member functions)
Mentry, Mdisplay (derived from Marks class) alone can be accessed.
Personal class public member functions can not be accessed because Marks class inherited under private visibility mode.

4.8 1) Data members
• Total, Agg, Final Grade and Commence of its own class
• M, Grade from Marks class can be accessed.
Personal class data members can not be accessed because Marks class inherited under private visibility mode.

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

2) Member functions
Mentry and Mdisplay from Marks class can be invoked from Result class member
Personal class member-functions can not be accessed because Marks class inherited under private visibility mode.

Question 5.
Write the output of the following program.
#include
using namespace std;
class A
{
protected:
int x;
public:
void show()
{
cout<<“x = “<<x<<endl;
}
A()
{
cout<<endl<<” I am class A “<<endl;
}
~A()
{
cout<<endl<<” Bye”; } }; class B : public A { protected: int y; public: B(int x, int y) { //this -> is used to denote the objects datamember this->x = x;
//this -> is used to denote the objects datamember this->y = y;
}
B()
{
cout<<endl<<“I am class B”<<endl;
}
~B()
{
cout<<endl<<” Bye”;
}
void show()
{
cout<<“x = “<<x<<endl;
cout<<“y = “<<y<<endl;
}
};
int main()
{
A objA;
B objB(30, 20);
objB.show();
return 0;
}
Output:
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 11

Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance

Question 6.
Debug the following program.
Output:
—————
15
14
13

PROGRAM :
%include(iostream.h)
#include
Class A
{
public;
int al,a2:a3;
void getdata[]
{
al=15;
a2=13;a3=13;
}
}
Class B:: public A()
{
PUBLIC
voidfunc()
{
int bl:b2:b3;
A::getdata[];
b1=a1;
b2=a2;
a3=a3;
cout<<b1<<‘\t'<<b2<<‘t\'<<b3;
}
void main()
{
clrscr()
B der;
derl:func();
getch();
}

Modified Error Free Program
using namespace std;
#include
#include
class A
{
public:
int al,a2,a3;
void getdata()
{
a1=15;
a2=14;
a3=13;
}
};
class B : public A
{
public:
void func()
{
int b1,b2,b3;
A::getdata();
b1=a1;
b2=a2;
b3=a3;
cout<<b1<<‘\n'<<b2<<‘\n'<<b3;
}
};
int main()
{
B der;
der.func();
getch();
return 0;
}
Samacheer Kalvi 11th Computer Science Guide Chapter 16 Inheritance 12

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top