Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Students can Download Computer Science Chapter 16 Inheritance Questions and Answers, Notes Pdf, Samacheer Kalvi 11th Computer Science Book Solutions Guide Pdf helps you to revise the complete Tamilnadu State Board New Syllabus and score more marks in your examinations.

Tamilnadu Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Samacheer Kalvi 11th Computer Science Inheritance Text Book Back Questions and Answers

PART – 1
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 class student from the base class Shool?
(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 inheritance 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 Solutions 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 class?
(a) Private
(b) Public
(c) Protected
(d) All of these
Answer:
(a) Private

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

Question 6.
A class 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:
(c) Constructor

Samacheer Kalvi 11th Computer Science Solutions 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 class declaration answer the questions (from 9.1 to 9.4)
class vehicle
{ int wheels;
public:
void input_data(float,float);
void output_data();
protected:
int passenger;
};
class heavyvehicle : protected vehicle {
int diesel_petrol;
protected:
int load;
protected:
int load;
public:
voidread_data(float,float)
voidwrite_data(); };
class bus: private heavy vehicle {
charTicket[20];
public:
voidfetch_data(char); voiddisplay_data(); };
};

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 displaydata()
(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()
(d) All of these display_data()
Answer:
(d) All of these display_data()

Samacheer Kalvi 11th Computer Science Solutions 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()
(d) All of these display_data()
Answer:
(d) All of these display_data()

Question 10.
class x
{int a;
public :
x()
{}
};
class y
{ x x1;
public :
y()
{}
};
class z : public y, x
{ intb;
public:
z(){}
} z1;
What is the order of constructor for object z1 to be invoked?
(a) z, y, x, x
(b) x, y, z, x
(c) y, x, x, z
(d) x, y, z
Answer:
(c) y, x, x, z

PART – 2
II. Answers to all the questions

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:
A class that is used as the basis for inheritance is called a superclass or base class.

Question 3.
Why derived class is called a 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.

Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Question 4.
In what multilevel and multiple inheritances differ though both contain many base class?
Answer:
The derived class is a power-packed class, as it can add additional attributes and methods and thus enhance its functionality.

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.

PART – 3
III. Answers to all the questions

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 private.
  • The names of all base classes(parent classes) separated by a comma.

Question 2.
What are the differences between the members present in the private visibility mode and the members present in the public visibility mode?
Answer:
Members present in the private visibility mode:

  • Can be accessed only by the class members.
  • By default the members will be in private visibility mode.
  • When classes are inherited, private members are not inherited.

Members present in the public visibility mode:

  • Can be accessed by outside members also.
  • Members, to be in public visibility mode has to be specified explicitly.
  • When classes are inherited, the public members are inherited as private, protected and public members of the derived class.

Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

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

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

Polymorphism:

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

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.

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

  • Base class constructors are executed first, before the derived class constructors execution.
  • A 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 it starts executing from the leftmost base class.
  • In multilevel inheritance, the constructors will be executed in the order of inheritance.

Some facts about the execution of the destructor in inheritance.

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

PART – 4
IV. Answers to all the questions

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.
  2. Multiple Inheritance: When a derived class inherits from multiple base classes it is known as multiple inheritances.
  3. Hierarchical inheritance: When more than one derived class is created from a single base class, it is known as Hierarchical inheritance.
  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.
  5. Hybrid inheritance: When there is a combination of more than one type of inheritance, it is known as hybrid inheritance.
  6. Hence, it may be a combination of Multilevel and Multiple inheritances or Hierarchical and Multilevel inheritance or Hierarchical, Multilevel and Multiple inheritances.

Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Question 2.
Explain the different visibility modes through pictorial representation.
Answer:
An important feature of Inheritance is to know which member of the base class will be acquired by the derived class. This is done by using visibility modes. The accessibility of base class by the derived class is controlled by visibility modes. The three visibility modes are private, protected, and public.

The default visibility mode is private. Though visibility modes and access specifiers look similar, the main difference between them is Access specifiers control the accessibility of the members within the class whereas visibility modes control the access of inherited members within the class.

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 Solutions Chapter 16 Inheritance 1
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 Solutions Chapter 16 Inheritance 2
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 Solutions Chapter 16 Inheritance 3

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
{
charbcity[15];
char baddress[25];
protected:
intnoofemp;
public:
charbphone[2][10];
branch();
∼ branch();
void have data();
void give data();
};
class author: public branch, publisher
{
intaut_code;
charaname[20];
float income;
public:
author();
~author();
voidgetdata();
voidputdata();
};

Answer the following questions based on the above-given program:
Question 3.1.
Which type of Inheritance is shown in the program?
Answer:
Multiple inheritances.

Question 3.2.
Specify the visibility mode of base classes.
Answer:
Private for the publisher.
Public for a branch.

Question 3.3.
Give the sequence of Constructor/Destructor Invocation when object of the class author is created.
Answer:
branch(); // constructor of branch class
publisher (); // constructor of publisher class
author (); // constructor of author class
∼author (); // destructor of author class
∼publisher (); // destructor of publisher class
∼branch (); // destructor of branch class

Question 3.4.
Name the base class(/es) and derived class (/es).
Answer:
Base class(/es): branch and publisher
Derived class (/es): author.

Question 3.5.
Give a number of bytes to be occupied by the object of the following class:
(a) publisher
(b) branch
(c) author
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 4

Question 3.6.
Write the names of data members accessible from the object of class author.
Answer:
The data members that can be accessed is bphone[2][10].

Question 3.7.
Write the names of all member functions accessible from the object of the class author.
Answer:
Member functions that can be accessed are:
1. public member functions of branch have_data();
give_data();

2. public member functions of author:
getdata();
putdata();

Question 3.8.
Write the names of all members accessible from member functions of class author.
Answer:
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 5

Question 4.
Consider the following C++ code and answer the questions
Answer:
class Personal
{
int Class,Rno;
char Section;
protected:
char Name[20];
public:
personal();
void pentry();
voidPdisplay();
};
class Marks:private Personal
{
float M{5};
protected:
char Grade[5];
public:
Marks();
void M entry();
void M display 0;
};
class Result:public Marks
{
float Total, Agg;
public:
char FinalGrade, Commence[20];
Result();
void R calculate();
void R display();
}:

Question 4.1.
Which type of Inheritance is shown in the program?
Answer:
Multilevel inheritance.

Question 4.2.
Specify the visibility mode of base classes.
Answer:
Private for personal public for marks.

Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Question 4.3.
Give the sequence of Constructor/Destructor Invocation when the object of class Result is created.
Answer:
Personal (); // constructor of class personal
Marks (); // constructor of class marks
Result (); // destructor of class Result
Marks (); // destructor of class marks
Personal (); // destructor of class personal

Question 4.4.
Name the base class(/es) and derived class (/es).
Answer:
Base class of marks: → Personal
Base class of Result: → Marks
Derived classes: → Marks and Results

Question 4.5.
Give a number of bytes to be occupied by the object of the following class:
(a) Personal
(b) Marks
(c) Result
Answer:
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 6

Question 4.6.
Write the names of data members accessible from the object of class Result.
Answer:
Data members accessible are:

  1. The private, public, and protected data members of personal cannot be accessed.
  2. The public data members of marks: Nil (i/7) Public data members of Result char Final Grade; char commence [20];

Question 4.7.
Write the names of all member functions accessible from the object of class Result. Member functions accessible are:
Answer:
1. The private, public and protected member functions of personal cannot be accessed.

2. The public member functions of marks
void mentry();
void
mdisplay();

3. Public member functions of Result
void Rcalculate();
void Rdisplay();

Question 4.8.
Write the names of all members accessible from member functions of class Result.
Answer:
Data members accessible
char Grade[5];
float Total;
float Age;
char Final Grade;
char Commence[20];

Member functions accessible
void mentry();
void mdisplay();
void Rcalculate();
void Rdisplay();

Question 5.
Write the output of the following program
Answer:
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 7
Output:
I am class A
I am class B
X = 30 Y = 20
Bye Bye
Bye

Question 6.
Debug the following program.
Answer:
Output:
…………………
15
14
13
Program:
…………………
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 8

Samacheer Kalvi 11th Computer Science Arrays and Structures Additional Questions and Answers

PART – 1
I. Choose the correct answer

Question 1.
When a derived class inherits only from one base class, it is known as ………………
(a) multiple inheritances
(b) multilevel inheritance
(c) hierarchical inheritance
(d) single inheritance
Answer:
(d) single inheritance

Question 2.
A class that inherits from a superclass is called ………………
(a) derived class
(b) superclass
(c) base class
(d) parent class
Answer:
(a) derived class

Question 3.
When more than one derived classes are created from a single base class, it is called ………………
(a) inheritance
(b) hybrid inheritance
(c) hierarchical inheritance
(d) multiple inheritances
Answer:
(c) hierarchical inheritance

Question 4.
……………… pointer is a constant pointer that holds the memory address of the current object.
(a) member function
(b) this pointer
(c) comma operator
(d) data member
Answer:
(b) this pointer

Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Question 5.
The ……………… are invoked in reverse order.
(a) constructor
(b) destructor
(c) pointer
(d) operator
Answer:
(b) destructor

PART – 2
II. Very Short Answers

Question 1.
Write a short note on hierarchical inheritance.
Answer:
When more than one derived class is created from a single base class, it is known as Hierarchical inheritance.

Question 2.
Write the syntax for derived and base class.
Answer:
class derived class name : visibility_mode baseclassname
{

// members of derivedclass

};

Question 3.
Explain the significance of different visibility modes with a program.
Answer:
Implementation of Single Inheritance using public visibility mode
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 9
Output:
Total area: 35

Question 4.
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.
Answer:
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 10

PART – 3
III. Short Answers

Question 1.
What are inheritance and access control?
Answer:
When you declare a derived class, a visibility mode can precede each base class in the base list of the derived class. This does not alter the access attributes of the individual members of a base class but allows the derived class to access the members of a base class with restriction. Classes can be derived using any of the three visibility modes:

  1. In a public base class, public and protected members of the base class remain public and protected members of the derived class.
  2. In a protected base class, public and protected members of the base class are protected members of the derived class.
  3. In a private base class, public and protected members of the base class become private members of the derived class.
  4. In all these cases, private members of the base class remain private and cannot be used by the derived class.
  5. However, it can be indirectly accessed by the derived class using the public or protected member function of the base class since they have the access privilege for the private members of the base class.

Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance

Question 2.
Write the derived class using any of the three visibility mode.
Answer:
Classes can be derived using any of the three visibility mode:

  1. In a public base class, public and protected members of the base class remain public and protected members of the derived class.
  2. In a protected base class, public and protected members of the base class are protected members of the derived class.
  3. In a private base class, public and protected members of the base class become private members of the derived class.

PART – 4
IV. Explain in Detail

Question 1.
Explain single inheritance with example.
Answer:
When a derived class inherits only from one base class, it is known as single inheritance.
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 11
Output
Enter roll no and name .. 1201 KANNAN
Enter lang, eng, phy, ehe, esc,mat marks.. 100 100 100 100 100 100
Roll no :- 1201
Name :- KANNAN
Marks Obtained
Language.. 100
English .. 100
Physics .. 100
Chemistry .. 100
Comp.sci .. 100
Maths .. 100

Question 2.
Explain this pointer.
Answer:
‘this’ pointer is a constant pointer that holds the memory address of the current object. It identifies the currently calling object.lt is useful when the argument variable name in the member function and the data member name are same.
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 12
Output:
5 5
5 5
Process exited after 0.1 seconds with return value 0
Press any key to continue…

Question 3.
Write the output of the following program.
Samacheer Kalvi 11th Computer Science Solutions Chapter 16 Inheritance 13
Answer:
Output:
My profession is: Teacher
My age is: 20
I can walk
I can talk.
I can teach computer.
My profession is: Footballer
My age is: 19
I can walk
I can talk.
I can play football.