Download Class 12 Computer Science Practice Worksheets
Access comprehensive chapter-wise worksheets for Inheritance using the CBSE Class 12 Computers Inheritance Worksheet. Designed to align with the 2026-27 academic syllabus for Class 12 Computer Science, these printable practice sets help students reinforce key concepts and improve their overall exam readiness.
Access Inheritance Practice Papers and Solutions
Navigate directly to the solved Computer Science worksheets using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.
Question 1. Discuss the relationship between base and derived classes.
Answer: The relationship between a base class and a derived class is known as an "IS-A" relationship or inheritance relationship. A base class (also called parent or superclass) is the generalized class containing common attributes and methods, while a derived class (also called child or subclass) is the specialized class that inherits the properties and behaviors of the base class. The derived class can reuse existing code from the base class, extend it with new data members and member functions, or override existing methods to provide specific functionality.
In simple words: A derived class is a specialized version of a base class, sharing its features while adding its own unique properties and behaviors.
Exam Tip: Always mention the term "IS-A relationship" and code reusability when explaining base and derived classes for full marks.
Question 2. List and explain the various types of inheritance with examples.
Answer: The major types of inheritance in C++ are:
1. Single Inheritance: A derived class inherits from only one base class. For example, class Dog inherits from class Animal.
2. Multilevel Inheritance: A class is derived from another derived class, forming a chain. For example, class Puppy inherits from class Dog, which in turn inherits from class Animal.
3. Multiple Inheritance: A derived class inherits from more than one base class. For example, class TeachingAssistant inherits from both class Teacher and class Student.
4. Hierarchical Inheritance: Multiple derived classes inherit from a single base class. For example, both class Dog and class Cat inherit from class Animal.
5. Hybrid Inheritance: A combination of two or more types of inheritance (such as multiple and hierarchical), often leading to the diamond problem which is resolved using virtual base classes.
In simple words: Inheritance types describe how parent and child classes are connected - whether one child has one parent, multiple parents, or shares a parent with other children.
Exam Tip: Draw simple block diagrams for each type of inheritance to make your answer visually clear and impactful.
Question 3. Discuss the inheritability of public, private and protected members in
a. Public inheritance
b. Private inheritance
c. Protected inheritance
Answer:
a. Public inheritance: Public members of the base class become public in the derived class, protected members remain protected, and private members remain inaccessible directly from the derived class.
b. Private inheritance: Public and protected members of the base class become private in the derived class, while private members remain inaccessible.
c. Protected inheritance: Public and protected members of the base class become protected in the derived class, while private members remain inaccessible.
In simple words: The visibility mode acts as an upper limit; member access can become more restricted in the derived class depending on the inheritance mode used.
Exam Tip: Memorize the access specifier matrix table (Base member vs. Inheritance mode = Derived member access) as this is a frequent board exam question.
Question 4. What is the effect of inheritance on the calling of
a. Default constructors and destructors
b. User-defined constructors and destructors
Explain with example.
Answer:
a. Default constructors and destructors: When an object of a derived class is created, the base class default constructor is executed first, followed by the derived class default constructor. Conversely, destruction occurs in the exact reverse order: the derived class destructor executes first, followed by the base class destructor.
b. User-defined constructors and destructors: When base class constructors take arguments, the derived class constructor must explicitly call the parameterized base class constructor using an initializer list. Destructors do not take arguments, so they follow the same reverse order of execution automatically.
Example:
class Base { public: Base() { cout << "Base Constructor"; } ~Base() { cout << "Base Destructor"; } };
class Derived : public Base { public: Derived() { cout << "Derived Constructor"; } ~Derived() { cout << "Derived Destructor"; } };
Output on object creation: Base Constructor Derived Constructor Derived Destructor Base Destructor.
In simple words: Base comes first during construction, but leaves last during destruction (First-In, Last-Out order).
Exam Tip: Emphasize that base constructors execute top-to-bottom while destructors execute bottom-to-up.
Question 5. Refer to Q8 of Assignment-3. Derive two classes from Box - Gift-wrapped box and Storage Box. Add the following functionalities to them:
a. Gift-wrapped box - Color of wrapping paper (default as red and as taken from user)
b. Storage box - Nos. required (default as 1 and as taken from user)
Answer:
#include <iostream>
#include <string>
using namespace std;
class Box {
protected:
float length, breadth, height;
public:
void getBox() {
cout << "Enter dimensions (L B H): ";
cin >> length >> breadth >> height;
}
void showBox() {
cout << "Dimensions: " << length << " x " << breadth << " x " << height << endl;
}
};
class GiftWrappedBox : public Box {
string color;
public:
GiftWrappedBox() { color = "red"; }
void getGiftBox() {
getBox();
cout << "Enter wrapping paper color: ";
cin >> color;
}
void showGiftBox() {
showBox();
cout << "Wrapping Color: " << color << endl;
}
};
class StorageBox : public Box {
int nos;
public:
StorageBox() { nos = 1; }
void getStorageBox() {
getBox();
cout << "Enter number of boxes required: ";
cin >> nos;
}
void showStorageBox() {
showBox();
cout << "Number Required: " << nos << endl;
}
};
In simple words: Both specialized boxes inherit basic dimensions from the Box class and add their own specific attributes (color and quantity) with default constructor values.
Exam Tip: Initialize default values correctly inside default constructors of derived classes and ensure base class input methods are invoked properly.
Question 6. Explain the following with examples:
a. Abstract class
b. Virtual keyword
c. Containership
Answer:
a. Abstract class: A class is abstract if it has at least one pure virtual function (a function equated to zero). Objects of an abstract class cannot be instantiated; it serves only as a base class for other classes.
Example: class Shape { public: virtual void draw() = 0; };
b. Virtual keyword: Used in C++ to achieve polymorphism and dynamic binding. When a base class pointer points to a derived class object, declaring the member function as virtual ensures that the derived class version of the function is called at runtime.
Example: virtual void display();
c. Containership (Composition): A design technique where an object of one class is contained within another class as a data member (often referred to as a HAS-A relationship).
Example: class Engine { ... }; class Car { Engine e; ... };
In simple words: An abstract class cannot make objects, virtual functions enable dynamic method overriding, and containership means having an object inside another object.
Exam Tip: Clearly state that abstract classes act as blueprints and cannot have direct object instantiation.
Question 7. What is the effect of containership in the calling of constructors and destructors? Explain with example.
Answer: In containership (where class A contains an object of class B), when an object of the container class (class A) is created, the constructor of the contained class (class B) is executed first, followed by the constructor of the container class (class A). When the container object goes out of scope, the destructor of the container class executes first, followed by the destructor of the contained class.
Example:
class Engine { public: Engine() { cout << "Engine Created\n"; } ~Engine() { cout << "Engine Destroyed\n"; } };
class Car { Engine e; public: Car() { cout << "Car Created\n"; } ~Car() { cout << "Car Destroyed\n"; } };
Output: Engine Created, Car Created, Car Destroyed, Engine Destroyed.
In simple words: Contained objects are built before the outer object is built, and destroyed after the outer object is destroyed.
Exam Tip: Contrast containership order with inheritance order: in containership, member objects are constructed first, whereas in inheritance, base class subobjects are constructed first.
Question 8. Create the following class hierarchy in C++.
Answer:
#include <iostream>
#include <string>
using namespace std;
class student {
protected:
string name;
int age;
public:
void readData() {
cout << "Enter name and age: ";
cin >> name >> age;
}
void display() {
cout << "Name: " << name << "\nAge: " << age << endl;
}
};
class BOOK {
protected:
string bookname, author;
int pages;
public:
void readB() {
cout << "Enter book name, author, pages: ";
cin >> bookname >> author >> pages;
}
void displayB() {
cout << "Book: " << bookname << "\nAuthor: " << author << "\nPages: " << pages << endl;
}
};
class EQUIPMENT {
protected:
string equipname, role;
public:
void readEqup() {
cout << "Enter equipment name and role: ";
cin >> equipname >> role;
}
void displayE() {
cout << "Equipment: " << equipname << "\nRole: " << role << endl;
}
};
class Primarystudent : public student {
string activity;
int hours;
public:
void readP() {
readData();
cout << "Enter activity and hours: ";
cin >> activity >> hours;
}
void displayP() {
display();
cout << "Activity: " << activity << "\nHours: " << hours << endl;
}
};
class Secondarystudent : public student {
BOOK b;
EQUIPMENT e;
public:
void readSec() {
readData();
b.readB();
e.readEqup();
}
void displaySec() {
display();
b.displayB();
e.displayE();
}
};
In simple words: Primarystudent inherits from student (IS-A), while Secondarystudent inherits from student (IS-A) and contains BOOK and EQUIPMENT objects (HAS-A).
Exam Tip: Carefully distinguish between IS-A relationships (public inheritance) and HAS-A relationships (object containment) as depicted in the UML diagram.
1. What is the need for inheritance? What are various types of inheritance?
2. What are the 3 ways in which class can be derived?
3. What is abstract class? How does it differs from concrete class?
4. How are constructors invoked in the derived class?
5. Why the access to global variable is not possible in the derived class member function which is of same name as that of a private data member of the base class ?
6. Class “a” has public member x. When class “b” is derived from “a” publically can x be made private explicitly in class “b”?
7. Give example of multiple inheritance
8. Why are classes sometimes derived virtually?
9. Give the significance of protected members.
10. What is the size of the derived class object?
11. How does invoking of constructor differ in inheritance and containership?
12. Give an example of multi level inheritance .
13. What is the difference between friendship and derivation?
14. Class “a” is derived from class “b” which is derived from class “c”. What is the order of invoking of constructors and destructors of these classes ?
15. Differentiate between containership and inheritance
Free study material for Computer Science
Free CBSE Practice Worksheets: Class 12 Computer Science Inheritance
Download Chapter Worksheets: Class 12 Computer Science
Access structured practice worksheets for Inheritance aligned with the 2026 CBSE curriculum. These downloadable exercises for Class 12 Computer Science help students build accuracy and reinforce core concepts for upcoming school tests.
Concept Clarification for Inheritance
Designed around the official curriculum for Class 12 Computer Science, these practice sheets guarantee standard compliance. Reviewing step-by-step solutions after completion sharpens your accuracy and clarifies complex sub-topics within Inheritance.
Effective Revision Strategies for School Exams
Consistent engagement with these exercises builds familiarity with recurring exam themes. If specific areas within Inheritance cause trouble, utilize our dedicated NCERT solutions for Class 12 Computer Science to clear up doubts immediately.
FAQs
You can download the latest chapter-wise printable worksheets for Class 12 Computer Science Inheritance for free from StudiesToday.com. These have been made as per the latest CBSE curriculum for this academic year.
Yes, Class 12 Computer Science worksheets for Inheritance focus on activity-based learning and also competency-style questions. This helps students to apply theoretical knowledge to practical scenarios.
Yes, we have provided solved worksheets for Class 12 Computer Science Inheritance to help students verify their answers instantly.
Yes, our Class 12 Computer Science test sheets are mobile-friendly PDFs and can be printed by teachers for classroom.
For Inheritance, regular practice with our worksheets will improve question-handling speed and help students understand all technical terms and diagrams.