C++ Inheritance Questions
Asked in Board Examination
Q&A
Q1(CBSE 2004): What is inheritance? Give an example in C++ to show its implementation in C++.
Answer: Inheritance is the process of forming a new class from an existing or base class. The base class is also known as parent class or super class. It allows the new class (called derived class) to inherit properties of its parent class.Inheriatnce helps in reusability of code.
For example, a class Truck inherits from class Automobiles which itself inherits from another class vehicles.
Q2(CBSE 2004): Given the following class definitions, answer the following questions.
(i) Name the members, which can be accessed from the member functions of class PhysicsBook.
(ii) Name the members, which can be accessed by an object of class TextBook.
(iii) Name the members which can be accessed by an object of class Physicsbook.
(iv) What will be the size of an object (in bytes) of class Physicsbook?
Answer: (i) no_of_chapters, no_of_assignments, standard, topic, readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook().
(ii) read(), show(), readtextbook(), showtextbook()
(iii) readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook()
(iv)20 + 20 + 2 + 2 + 2 + 2 + 20 = 68 bytes.
Q3 (CBSE 2013): Consider the following c++ code and answer the questions (i) to (iv):
Answer: Inheritance is the process of forming a new class from an existing or base class. The base class is also known as parent class or super class. It allows the new class (called derived class) to inherit properties of its parent class.Inheriatnce helps in reusability of code.
For example, a class Truck inherits from class Automobiles which itself inherits from another class vehicles.
Q2(CBSE 2004): Given the following class definitions, answer the following questions.
class Book
{
char title[20];
char author[20];
int no_of_pages;
public:
void read( );
void show( );
};
class TextBook : private Book
{
int no_of_chapters, no_of_assignments;
protected:
int standard;
public:
void readtextbook( );
void showtextbook( );
};
class PhysicsBook : public TextBook
{
char topic[20];
public:
void readphysicsbook( );
void showphysicsbook( );
};
(i) Name the members, which can be accessed from the member functions of class PhysicsBook.
(ii) Name the members, which can be accessed by an object of class TextBook.
(iii) Name the members which can be accessed by an object of class Physicsbook.
(iv) What will be the size of an object (in bytes) of class Physicsbook?
Answer: (i) no_of_chapters, no_of_assignments, standard, topic, readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook().
(ii) read(), show(), readtextbook(), showtextbook()
(iii) readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook()
(iv)20 + 20 + 2 + 2 + 2 + 2 + 20 = 68 bytes.
Q3 (CBSE 2013): Consider the following c++ code and answer the questions (i) to (iv):









