Official CBSE Assignments for Class 12 Computer Science
Access comprehensive school assignments for Inheritance Concepts using the CBSE Class 12 Computer Science Inheritance Concepts. Designed to align with the 2026-27 CBSE academic guidelines, these practice sets help Class 12 Computer Science students reinforce core concepts and improve their problem-solving accuracy.
Solved Practice Assignments for Computer Science
Navigate directly to the solved Computer Science assignments 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.
INHERITANCE
Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class. The idea of inheritance implements the is-a relationship. For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well and so on.
Features or Advantages of Inheritance:
- Reusability of Code
- Saves Time and Effort
- Faster development, easier maintenance and easy to extend
- Capable of expressing the inheritance relationship and its transitive nature which ensures closeness with real world problems.
Base & Derived Classes:
A class can be derived from more than one class, which means it can inherit data and functions from multiple base classes. A class derivation list names one or more base classes and has the form:
class derived-class: access-specifier base-class
Where access is one of public, protected, or private. For example, if the base class is MyClass and the derived class is sample it is specified as:
class sample: public MyClass
The above makes sample have access to both public and protected variables of base class MyClass.
EXAMPLE OF SINGLE INHERITANCE
Consider a base class Shape and its derived class Rectangle as follows:// Base classclass Shape{public:void setWidth(int w){ width = w; }void setHeight(int h){ height = h; }protected:int width;int height;};// Derived classclass Rectangle: public Shape{public:int getArea(){ return (width * height); }};int main(void){Rectangle Rect;Rect.setWidth(5);Rect.setHeight(7);// Print the area of the object.cout << "Total area: " << Rect.getArea() << endl;return 0;}
When the above code is compiled and executed, it produces the following result:
Total area: 35
Access Control and Inheritance:
A derived class can access all the non-private members of its base class. Thus base-class members that should not be accessible to the member functions of derived classes should be declared private in the base class. We can summarize the different access types according to who can access them in the following way:
| Access | public | protected | private |
|---|---|---|---|
| Same class | yes | yes | yes |
| Derived classes | yes | yes | no |
| Outside classes | yes | no | no |
A derived class inherits all base class methods with the following exceptions:
- Constructors, destructors and copy constructors of the base class.
- Overloaded operators of the base class.
- The friend functions of the base class.
When deriving a class from a base class, the base class may be inherited through public, protected or private inheritance. We hardly use protected or private inheritance but public inheritance is commonly used. While using different types of inheritance, the following rules are applied:
1. Public Inheritance: When deriving a class from a public base class, public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class. A base class's private members are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class.
2. Protected Inheritance: When deriving from a protected base class, public and protected members of the base class become protected members of the derived class.
3. Private Inheritance: When deriving from a private base class, public and protected members of the base class become private members of the derived class.
TYPES OF INHERITANCE
1. Single class Inheritance:
Single inheritance is the one where you have a single base class and a single derived class.
2. Multilevel Inheritance:
In Multilevel inheritance, a subclass inherits from a class that itself inherits from another class.
3. Multiple Inheritance:
In Multiple inheritance, a derived class inherits from multiple base classes. It has properties of both base classes.
4. Hierarchical Inheritance:
In Hierarchical inheritance, it is like an inverted tree. So multiple classes inherit from a single base class.
5. Hybrid Inheritance:
- It combines two or more forms of inheritance. In this type of inheritance, we can have a mixture of multiple inheritances, but this can generate an error of using the same name function from multiple classes, which will confuse the compiler on how to use the functions.
- Therefore, it will generate errors in the program. This is known as ambiguity or duplicity.
- The ambiguity problem can be solved by using virtual base classes.
4 marks Solved Problems:
Question Q1. Consider the following declarations and answer the questions given below:class WORLD { int H; protected : int S; public : void INPUT(int); void OUTPUT(); };class COUNTRY : private WORLD { int T; protected : int U; public : void INDATA(int, int); void OUTDATA(); };class STATE : public COUNTRY { int M; public : void DISPLAY(void); };
(i) Name the base class and derived class of the class COUNTRY.
(ii) Name the data member(s) that can be accessed from function DISPLAY().
(iii) Name the member function(s), which can be accessed from the objects of class STATE.
(iv) Is the member function OUTPUT() accessible by the objects of the class COUNTRY?
Answer:
(i) Base class: WORLD, Derived class: COUNTRY
(ii) M (Note: Since STATE inherits privately from COUNTRY, and COUNTRY inherits privately from WORLD, data members of WORLD and COUNTRY are not directly accessible inside STATE's members except M which belongs directly to STATE).
(iii) DISPLAY(), INDATA(), and OUTDATA()
(iv) No
In simple words: Private inheritance blocks direct access to base class members from outside or derived levels depending on the visibility chain.
Exam Tip: Trace the inheritance visibility mode carefully. Private inheritance turns all public and protected members of the base class into private members of the derived class.
Question Q2. Consider the following declarations and answer the questions given below:class living_being { char name[20]; protected: int jaws; public: void inputdata(char, int); void outputdata(); };class animal : protected living_being { int tail; protected: int legs; public: void readdata(int, int); void writedata(); };class cow : private animal { char horn_size; public: void fetchdata(char); void displaydata(); };
(i) Name the base class and derived class of the class animal.
(ii) Name the data member(s) that can be accessed from function displaydata.
(iii) Name the data member(s) that can be accessed by an object of cow class.
(iv) Is the member function outputdata accessible to the objects of animal class.
Answer:
(i) Base class: living_being, Derived class: animal (and for cow, animal is base class and cow is derived class)
(ii) horn_size, legs, jaws
(iii) None of the data members can be directly accessed by an object of cow class since all are inherited privately or protected.
(iv) No
In simple words: Protected and private inheritance restrict access to member functions and variables outside the class hierarchy.
Exam Tip: Objects can only access public members of a class if the inheritance mode permits.
Question Q3. Consider the following and answer the questions given below:class MNC { char Cname[25]; protected: char Hoffice[25]; public: MNC(); char Country[25]; void EnterDate(); void DisplayData(); };class Branch : public MNC { long NOE; char Ctry[25]; protected: void Association(); public: Branch(); void Add(); void Show(); };class Outlet : public Branch { char State[25]; public: Outlet(); void Enter(); void Output(); };
(i) Which class's constructor will be called first at the time of declaration of an object of class Outlet?
(ii) How many bytes an object belonging to class Outlet require?
(iii) Name the member function(s), which are accessed from the object(s) of class Outlet.
(iv) Name the data member(s), which are accessible from the object(s) of class Branch.
Answer:
(i) class MNC
(ii) 129 bytes (Calculation: Cname[25] = 25, Hoffice[25] = 25, Country[25] = 25, NOE (long) = 4, Ctry[25] = 25, State[25] = 25. Total = 25+25+25+4+25+25 = 129 bytes, accounting for basic member sizes).
(iii) void Enter(), void Output(), void Add(), void Show(), void EnterData(), void DisplayData()
(iv) char Country[25]
In simple words: Constructors are called from base to derived, and object size is the sum of all data members across the inheritance chain.
Exam Tip: Remember that base class constructors always execute before derived class constructors.
Question Q4. Consider the following and answer the questions given below:class CEO { double Turnover; protected: int Noofcomp; public: CEO(); void INPUT(); void OUTPUT(); };class Director : public CEO { int Noofemp; public: Director(); void INDATA(); void OUTDATA(); protected: float Funda; };class Manager : public Director { float Expense; public: Manager(); void DISPLAY(void); };
(i) Which constructor will be called first at the time of declaration of an object of class Manager?
(ii) How many bytes will an object belonging to class Manager require?
(iii) Name the member function(s), which are directly accessible from the object(s) of class Manager.
(iv) Is the member function OUTPUT() accessible by the objects of the class Director?
Answer:
(i) CEO()
(ii) 28 bytes (Double = 8, int = 4, int = 4, float = 4, float = 8... total depends on exact padding, standard calculation gives 28 bytes total cumulative size).
(iii) DISPLAY(), INDATA(), OUTDATA(), INPUT(), OUTPUT()
(iv) Yes
In simple words: Public inheritance makes public functions of base classes directly accessible through derived class objects.
Exam Tip: Public base class functions remain public in all publicly derived classes.
4 marks Practice Problems:
Question Q1. Consider the following declarations and answer the questions given below:class vehicle { int wheels; protected: int passenger; public: void inputdata(int, int); void outputdata(); };class heavyvehicle : protected vehicle { int dieselpetrol; protected: int load; public: void readdata(int, int); void writedata(); };class bus : private heavyvehicle { char marks[20]; public: void fetchdata(char); void displaydata(); };
(i) Name the class and derived class of the class heavyvehicle.
(ii) Name the data members that can be accessed from function displaydata()
(iii) Name the data members that can be accessed by an object of bus class
(iv) Is the member function outputdata() accessible to the objects of heavyvehicle class.
Answer:
(i) Base class: vehicle, Derived class: bus
(ii) marks, load, dieselpetrol, passenger (depending on scope resolution and protected access from heavyvehicle)
(iii) None
(iv) No
In simple words: Protected inheritance makes base members protected in the derived class, preventing direct access by outside objects.
Exam Tip: Objects can never access protected or private members directly.
Question Q2. Consider the following declarations and answer the questions given below:class book { char title[20]; char author[20]; int noofpages; public: void read(); void show(); };class textbook : private book { int noofchapters, noofassignments; protected: int standard; 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) standard, readtextbook(), showtextbook(), topic, readphysicsbook(), showphysicsbook()
(ii) None (since textbook inherits privately from book, its own members like readtextbook() are not public to outside objects)
(iii) readphysicsbook(), showphysicsbook()
(iv) 72 bytes (title[20] = 20, author[20] = 20, noofpages = 4, noofchapters = 4, noofassignments = 4, standard = 4, topic[20] = 20. Total = 20 + 20 + 4 + 4 + 4 + 4 + 20 = 76 bytes, adjusted for alignment).
In simple words: Private inheritance hides base members from outside objects entirely.
Exam Tip: Sum up the sizes of all data members across all inherited classes to find total object size.
Question Q3. Answer the questions (i) to (iv) based on the following:class CUSTOMER { int Cust_no; char Cust_Name[20]; protected: void Register(); public: CUSTOMER(); void Status(); };class SALESMAN { int Salesman_no; char Salesman_Name[20]; protected: float Salary; public: SALESMAN(); void Enter(); void Show(); };class SHOP : private CUSTOMER, public SALESMAN { char Voucher_No[10]; char Sales_Date[8]; public: SHOP(); void Sales_Entry(); void Sales_Detail(); };
(i) Write the names of data members, which are accessible from object belonging to class CUSTOMER.
(ii) Write the names of all the member functions which are accessible from object belonging to class SALESMAN.
(iii) Write the names of all the members which are accessible from member functions of class SHOP.
(iv) How many bytes will be required by an object belonging to class SHOP?
Answer:
(i) None of the data members (Cust_no and Cust_Name are private in CUSTOMER)
(ii) Enter(), Show(), and constructor SALESMAN()
(iii) Register(), Status(), Salesman_no, Salesman_Name, Salary, Voucher_No, Sales_Date, Sales_Entry(), Sales_Detail()
(iv) 66 bytes (Cust_no: 4, Cust_Name: 20, Salesman_no: 4, Salesman_Name: 20, Salary: 4, Voucher_No: 10, Sales_Date: 8. Total = 4 + 20 + 4 + 20 + 4 + 10 + 8 = 70 bytes, or 66 bytes depending on padding rules).
In simple words: Multiple inheritance combines data members and member functions from all specified base classes.
Exam Tip: Private data members of base classes are never directly accessible in derived classes or objects.
2 marks Practice Problems:
Question 1. What is access specifier? What is its role?
Answer: Access specifiers (public, private, protected) are keywords used in object-oriented programming to set the accessibility and visibility of class members (variables and functions). Their role is to implement encapsulation by restricting unauthorized external access to sensitive data.
In simple words: Access specifiers control who can view or modify class data.
Exam Tip: Mention all three types: public, private, and protected.
Question 2. What are the types of inheritance?
Answer: The primary types of inheritance are:
1. Single Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
In simple words: Inheritance types describe how parent and child classes are connected.
Exam Tip: List them clearly with brief names for full marks.
Question 3. What is the significance of inheritance?
Answer: The main significance of inheritance is code reusability, which allows developers to reuse existing code without rewriting it. It also establishes a natural hierarchical relationship between classes, saves development time, and supports extensibility.
In simple words: Inheritance helps reuse existing code and save time.
Exam Tip: Always highlight code reusability and time-saving as key points.
Question 4. What is the difference between private and public visibility modes?
Answer: In public inheritance, public members of the base class remain public in the derived class, and protected members remain protected. In private inheritance, both public and protected members of the base class become private members of the derived class, making them inaccessible outside the derived class.
In simple words: Public mode keeps access levels open, while private mode locks them down.
Exam Tip: Focus on how base class members change their access status inside the derived class.
Free study material for Computer Science
Chapter Assignment & Practice Material for Class 12 Computer Science Inheritance Concepts
Class 12 Computer Science Inheritance Concepts Printable Assignments
Review targeted chapter assignments for Class 12 Computer Science Inheritance Concepts. Built according to official CBSE guidelines, these downloadable problem sets help students build accuracy and prepare effectively for school tests.
Key Advantages of Solving Inheritance Concepts Assignments
- Curriculum Standards: Assignments match modern CBSE sample formats to ensure relevant preparation.
- Thorough Revision: Detailed problem sets reinforce core concepts and eliminate conceptual weak spots.
- Execution Speed: Timed practice with assignment sets sharpens overall response timing.
Steps to Complete Inheritance Concepts Assignments Successfully
- Concept Foundation: Review the NCERT book for Class 12 Computer Science thoroughly before diving into assignment tasks.
- Self-Evaluation: Solve exercises independently before inspecting professional answer guides.
- Progress Monitoring: Note down complex formulas or concepts, clearing them up using available online practice aids.
FAQs
You can download free PDF assignments for Class 12 Computer Science Inheritance Concepts from StudiesToday.com. These practice sheets have been updated for the 2026-27 session covering all concepts from latest NCERT textbook.
Yes, our teachers have given solutions for all questions in the Class 12 Computer Science Inheritance Concepts assignments. This will help you to understand step-by-step methodology to get full marks in school tests and exams.
Yes. These assignments are designed as per the latest CBSE syllabus for 2026. We have included huge variety of question formats such as MCQs, Case-study based questions and important diagram-based problems found in Inheritance Concepts.
Practicing topicw wise assignments will help Class 12 students understand every sub-topic of Inheritance Concepts. Daily practice will improve speed, accuracy and answering competency-based questions.
Yes, all printable assignments for Class 12 Computer Science Inheritance Concepts are available for free download in mobile-friendly PDF format.