0% found this document useful (0 votes)
11 views

Chapter 10 Inheritance

Chapter 10 discusses inheritance in C++, defining it as the capability of one class to inherit properties from another. It covers various types of inheritance such as single, multilevel, hierarchical, hybrid, and multiple inheritance, along with their advantages like code reuse and faster development. The chapter also explains visibility modes in inheritance, including public, private, and protected inheritance.

Uploaded by

athmikarai09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Chapter 10 Inheritance

Chapter 10 discusses inheritance in C++, defining it as the capability of one class to inherit properties from another. It covers various types of inheritance such as single, multilevel, hierarchical, hybrid, and multiple inheritance, along with their advantages like code reuse and faster development. The chapter also explains visibility modes in inheritance, including public, private, and protected inheritance.

Uploaded by

athmikarai09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CHAPTER 10- INHERITANCE

CHAPTER 10- INHERITANCE


One marks questions:
1. What is inheritance? (U)
ANS: Inheritance is the capability of one class to inherit properties from another class.

2. How is inheritance implemented in C++? (U)


ANS: C++ allows the user to create a new class (derived class) from an existing class (base

class).
3. What is a base class? (U)
ANS: Base Class is the class whose properties are inherited by another class. It is also called

Super class.
4. What is derived class? (U)
ANS: Derived Class is the class that inherits the properties from base class. It is also called

Sub class.
5. Give any one advantage of inheritance? (U)
ANS: Reusing existing code

6. What is singe level inheritance? (U)


ANS: Single Inheritance is the process of creating a new class from existing class base class.

7. What is multilevel inheritance? (U)


ANS: Derivation of a class from another derived class is called multilevel inheritance.

8. What is hierarchical inheritance? (U)


ANS: If a number of classes are derived from a single base class, it is called as hierarchical

inheritance.
9. What is hybrid inheritance? (U)
ANS: Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.

10. What is multiple inheritance? (U)


ANS: A class can be derived from more than one base calss is known as multiple inheritance.

11. When is it necessary to use inheritance? (A)

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 1


CHAPTER 10- INHERITANCE

ANS: Suppose X is a class already defined and we need to redefine another class Y has same

properties of X and in addition its own.


12. What is visibility mode? (U)
ANS: It specifies the availability of a class members in other classes.

13. What is a super class? (U)


ANS: Base Class or Super class is the class whose properties are inherited by another class.

14. What is a subclass? (U)


ANS: Derived Class or Sub class is the class that inherits the properties from base class.

Two marks questions:


1. Write any two advantages of inheritance. (U)
ANS: Reusing existing code

o Faster development time


o Easy to maintain
2. Mention any two types of inheritance? (U)
ANS: o Single Inheritance

o Multilevel Inheritance
3. What is single inheritance? Give an example. (U)
ANS: Single Inheritance is the process of creating a new class from existing class base class.

class Base_Class
{
………..
};
class Derived_class : public Base_calss
{
………..
Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 2
CHAPTER 10- INHERITANCE

};

4. What is multilevel inheritance? Give an example. (U)


ANS: Derivation of a class from another derived class is called multilevel inheritance.

5. What is hierarchical inheritance? Give an example. (U)


ANS: If a number of classes are derived from a single base class, it is called as hierarchical

inheritance.

6. What is hybrid inheritance? Give an example. (U)


ANS: Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.

7. What is multiple inheritance? Give an example. (U)


ANS: A class can be derived from more than one base calss is known as multiple inheritance.

8. Write the syntax to define a derived class. (U)

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 3


CHAPTER 10- INHERITANCE

ANS: class derived_class_name : Visibility Mode base_class_name

{ ……. };

Three marks questions:


1. Write any three advantages of inheritance. (U)
ANS:o Reusing existing code

o Faster development time


o Easy to maintain
o Easy to extend
o Memory Utilization

2. Mention any three types of inheritance? (U)


ANS:o Single Inheritance

o Multilevel Inheritance
o Multiple Inheritance
o Hierarchical Inheritance
o Hybrid Inheritance
3. Mention the types of inheritance. Explain any one. (K)
ANS:

Single Inheritance is the process of creating a new class from existing class base class.
It is very coomon in inheritance that a class is derived from the base class.
The data members and memberfunction of the base class are data member and member
function
of the derived class.
Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 4
CHAPTER 10- INHERITANCE

A derived class with single inheritance is declared as follows:

class Base_Class
{
………..
};
class Derived_class : public Base_calss
{
………..
};
4. Write the syntax and example to define a derived class. (U)
ANS: Defining Derived Classes:

A derived class is a composite class – it inherits members from the base class and adds
member of its own.
The general form of the derived class is given below.
Class derivedclassname : VisibilityMode base_class_name
o The use of a constructor can be cleverly done especially in those problems where it is
necessary to initialize certain data members compulsorily.
Example :- Public Derived_Class
class father //Base class
{
private:
char name[10];
public:
char caste[10];
int age;
void readdata( );
};

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 5


CHAPTER 10- INHERITANCE

class son : public father


{
private:
char gender[5];
public:
void display( );
};
5. Write an example for the use of constructors in single level inheritance. (A)
6. Explain public inheritance. (U)
ANS:Public Inheritance:

When a base class is inherited as public, all public members of the base class become public
members of derived class.
The private members of the base class remain private to that class, and are nor accessible by
members of the derived class.
7. Explain private inheritance. (U)
ANS: Private Inheritance:

When a base class is inherited as private, then all public and protected members of the base
class become private members of derived class.
This means that they are still accessible by member of the derived class, but cannot be
accessed by other parts of the program.
8. Explain protected inheritance. (U)
ANS: Protected Inheritance:

When a base class is inherited as protected, then all public and protected members of the
base class become protected members of derived class.
The private data members of base class are not visible to derived class.
They can only be accessed through public and protected member functions of base class.

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 6


CHAPTER 10- INHERITANCE

Example: A program illustrates protected inheritance with the base class having protected
and public members.
Five marks questions:
1. Explain the different types of inheritance. (U)
ANS: Inheritance:

Inheritance is the capability of one class to inherit properties from another class.
Types of Inheritance:
Based on the relationship, inheritance can be classified into five forms:
o Single Inheritance
o Multilevel Inheritance
o Multiple Inheritance
o Hierarchical Inheritance
o Hybrid Inheritance
Single Inheritance:

Single Inheritance is the process of creating a new class from existing class base class.
It is very coomon in inheritance that a class is derived from the base class.
Multilevel Inheritance:

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 7


CHAPTER 10- INHERITANCE

Derivation of a class from another derived class is called multilevel inheritance.


In the figure class A is the base class for class AB and class AB is the base class for class
ABC.
The class AB provides a link for the inheritance between A and ABC, and is known as

Multiple Inheritance:

A class can be derived from more than one base calss is known as multiple inheritance.
A derived class with multiple inheritance is declared as follows:
Hierarchical Inheritance:
If a number of classes are derived from a single base class, it is called as hierarchical
inheritance.
Hierarchical model exhibits top down approach by breaking up a complex class into simpler
class.

Hybrid Inheritance:

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 8


CHAPTER 10- INHERITANCE

Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.


2. What are the advantages of inheritance? (U)
ANS:
o Reusing existing code
o Faster development time
o Easy to maintain
o Easy to extend
o Memory Utilization
3. What is visibility mode? Explain private and public inheritance. (A)
ANS: Visibility mode:

Visibility mode can be public, private or protected. The private data of base class cannot be
inherited.
o public: If inheritance is done in public mode, public members of the base class become
the public member of derived class and protected member of base class become the
protected member of derived class..
o private: If inheritance is done in a private mode, public and protected members of base
class become the private members of derived class.
o protected: If inheritance is done in a protected mode, public and protected members of
base class become the protected members of the base class.
4. What is inheritance? Explain any two types of inheritance. (U)
ANS: Inheritance is the capability of one class to inherit properties from another class.

Single Inheritance:

Single Inheritance is the process of creating a new class from existing class base class.
It is very coomon in inheritance that a class is derived from the base class.
Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 9
CHAPTER 10- INHERITANCE

The data members and memberfunction of the base class are data member and member
function of the derived class.
A derived class with single inheritance is declared as follows:
class Base_Class
{
………..
};
class Derived_class : public Base_calss
{
………..
};
Multilevel Inheritance:

Derivation of a class from another derived class is called multilevel inheritance.


In the figure class A is the base class for class AB and class AB is the base class for class
ABC.
The class AB provides a link for the inheritance between A and ABC, and is known as
intermedidate base class.
5. What is inheritance? Explain multiple and multilevel inheritance. (U)
ANS: Inheritance is the capability of one class to inherit properties from another class.

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 10


CHAPTER 10- INHERITANCE

Multiple Inheritance:

Multilevel Inheritance:

Derivation of a class from another derived class is called multilevel inheritance.


In the figure class A is the base class for class AB and class AB is the base class for class
ABC.
The class AB provides a link for the inheritance between A and ABC, and is known as
intermedidate base class.
A class can be derived from more than one base calss is known as multiple inheritance.

6. What is inheritance? Explain any hierarchical and hybrid inheritance. (U)


ANS: Inheritance is the capability of one class to inherit properties from another class.

Hierarchical Inheritance:
If a number of classes are derived from a single base class, it is called as hierarchical
inheritance.
Hierarchical model exhibits top down approach by breaking up a complex class into simpler
class.

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 11


CHAPTER 10- INHERITANCE

Hybrid Inheritance:

Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.

Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy