Inheritance: book back answers
21 solved questions from the end of this chapter, Class 11 Computer Science, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.
← Notes and quiz for InheritanceSECTION – A — Choose the correct answer
Which of the following derives a class student from the base class school
- (a) school: student
- (b) class student : public school
- (c) student : public school
- (d) class school : public student
Try it, then show the answerAnswer
(b) class student : public school
A derived-class declaration gives the derived class name, a colon, the visibility mode, and the base class name.
From the book: “class derived_class_name :visibility_mode base_class_name”
The type of inheritance that reflects the transitive nature is
- (A) Single Inheritance
- (B) Multiple Inheritance
- (C) Multilevel Inheritance
- (D) Hybrid Inheritance
Try it, then show the answerAnswer
(C) Multilevel Inheritance
The chapter identifies multilevel inheritance as the form reflecting inheritance’s transitive nature.
From the book: “The transitive nature of inheritance is reflected by this form of inheritance.”
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
Try it, then show the answerAnswer
(A) Private
Private inheritance makes base-class features available to the derived class, but not to classes derived from it.
From the book: “Private inheritance 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.”
Inheritance is a process of creating new class from
- (A) Base class
- (B) abstract
- (C) derived class
- (D) Function
Try it, then show the answerAnswer
(A) Base class
Inheritance creates a derived class from an existing base class.
From the book: “It is a process of creating new classes called derived classes, from the existing or base classes.”
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
Try it, then show the answerAnswer
(B) multilevel inheritance
This is the chapter’s definition of multilevel inheritance.
From the book: “When a class is derived from a class which is a derived class – then it is referred to as multilevel inheritance.”
Which amongst the following is executed in the order of inheritance?
- (A) Destructor
- (B) Member function
- (C) Constructor
- (D) Object
Try it, then show the answerAnswer
(C) Constructor
Constructors run from the base class toward the derived class, in inheritance order.
From the book: “The constructors are executed in the order of inherited class i.e., from base constructor to derived.”
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
Try it, then show the answerAnswer
(B) Private members of base class are not inherited to the derived class with private accessibility
The chapter says private base-class members are not inherited; they remain inaccessible to the derived class.
From the book: “The private member of a class cannot be inherited .”
SECTION-B — Very Short Answers
What is inheritance?
Try it, then show the answerAnswer
Inheritance is the process of creating new classes from existing or base classes, allowing the new classes to acquire the base class’s properties.
A class derived from a base class can acquire its non-private code and add its own attributes and methods.
From the book: “Inheritance enables new class and its objects to take on the properties of the existing classes.”
What is a base class?
Try it, then show the answerAnswer
A base class is the existing class used as the basis for creating a new derived class.
It is also called a superclass or parent class.
From the book: “A class that is used as the basis for creating a new class is called a superclass or base class.”
Why derived class is called power packed class?
Try it, then show the answerAnswer
A derived class is called a power packed class because it can add additional attributes and methods to inherited features, enhancing its functionality.
The derived class acquires base-class properties and can extend them with its own members.
From the book: “The derived class is a power packed class, as it can add additional attributes and methods and thus enhance its functionality.”
In what multilevel and multiple inheritance differ though both contains many base class?
Try it, then show the answerAnswer
In multiple inheritance, a derived class inherits from multiple base classes. In multilevel inheritance, a class is derived from another class that is itself derived from a base class.
Multiple inheritance involves several base classes for one derived class; multilevel inheritance forms successive levels of derivation.
From the book: “When a derived class inherits from multiple base classes it is known as multiple inheritance”
What is the difference between public and private visibility mode?
Try it, then show the answerAnswer
With public visibility, base-class public members remain public and protected members remain protected in the derived class. With private visibility, both public and protected base-class members become private in the derived class.
The visibility mode determines the accessibility of inherited members.
From the book: “In privately derived class, the public and the protected members of the base class become private in derived class”
SECTION-C — Short Answers
What are the points to be noted while deriving a new class?
Try it, then show the answerAnswer
Use the keyword class, give the derived-class name, add a colon, specify a visibility mode (private, public or protected), and then give the base-class name. If there is more than one base class, separate the base-class names with commas. If no visibility mode is specified, it defaults to private.
These are the chapter’s stated requirements for defining a derived class.
From the book: “The name of the base class(parent class), if more than one base class, then it can be given separated by comma.”
What is difference between the members present in the private visibility mode and the members present in the public visibility mode
Try it, then show the answerAnswer
With private visibility, public and protected members of the base class become private members of the derived class. With public visibility, the base class’s public members remain public and its protected members remain protected; private base members are not inherited.
The visibility mode changes the accessibility of inherited members, not the original access specifiers inside the base class.
From the book: “In publicly derived class,the public members of the base class remain public and protected members of base class remain protected in derived class.”
What do you mean by overriding?
Try it, then show the answerAnswer
Function overriding occurs when a derived-class member function has the same name as a base-class member function, thereby hiding the inherited base-class function. The base-class function can be called using the base-class name followed by the scope resolution operator and function name.
The derived-class function has higher priority; scope resolution can be used to call the base-class version.
From the book: “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 .”
Write some facts about the execution of constructors and destructors in inheritance
Try it, then show the answerAnswer
When a derived-class object is created, the base-class constructor runs first, followed by the derived-class constructor. When the object expires, the derived-class destructor runs first, followed by the base-class destructor. Base-class constructors and destructors are not inherited, but base constructors are automatically invoked when a derived object is created.
Construction proceeds from base to derived, while destruction proceeds in reverse order.
From the book: “When an object of the derived class is created ,the compiler first call the base class constructor and then the constructor of the derived class.”
Explain in detail
Explain the different types of inheritance
Try it, then show the answerAnswer
Inheritance is the process of creating new classes from existing classes. The chapter describes five types of inheritance.
- Single inheritance: A derived class inherits from only one base class.
- Multiple inheritance: A derived class inherits from more than one base class.
- Hierarchical inheritance: More than one derived class is created from a single base class.
- Multilevel inheritance: A class is derived from another class that is itself a derived class. This reflects the transitive nature of inheritance.
- Hybrid inheritance: Hybrid inheritance is a combination of more than one type of inheritance.
Example: The chapter gives the example of class result being derived from exam, which is derived from student, as multilevel inheritance.
Thus, inheritance is classified into single, multiple, hierarchical, multilevel and hybrid inheritance.
From the book: “When there is a combination of more than one type of inheritance, it is known as hybrid inheritance.”
Explain the different visibility mode through pictorial representation
Try it, then show the answerAnswer
Visibility modes control the accessibility of inherited base-class members in the derived class. The three visibility modes are private, protected and public.
- Private visibility mode: With private inheritance, the base class’s public and protected members become private members of the derived class.
- Protected visibility mode: With protected inheritance, the base class’s public and protected members become protected members of the derived class.
- Public visibility mode: With public inheritance, the base class’s protected members remain protected, and its public members remain public in the derived class.
- Private base members: Private members of the base class are not inherited as accessible members in any visibility mode.
- Choosing a visibility mode: Private inheritance makes base-class features unavailable to classes derived from the derived class. Protected inheritance keeps them within the derived class, while public inheritance makes them available to the derived class and the outside world.
Thus, the visibility mode determines the access level of inherited public and protected members in the derived class.
From the book: “The accessibility of base class by the derived class is controlled by visibility modes.”
1. Which type of Inheritance is shown in the program?
Try it, then show the answerAnswer
The program is not included in the question, so its type of inheritance cannot be identified. Inheritance type depends on how the derived class or classes are related to their base class or classes.
- Single inheritance: If a derived class inherits from only one base class, it is single inheritance.
- Multiple inheritance: If a derived class inherits from multiple base classes, it is multiple inheritance.
- Hierarchical inheritance: If more than one derived class is created from one base class, it is hierarchical inheritance.
- Multilevel inheritance: If a class is derived from another class that is itself derived, it is multilevel inheritance.
- Hybrid inheritance: A combination of more than one type of inheritance is called hybrid inheritance.
The program code is needed to determine which of these inheritance types it shows.
From the book: “When a class is derived from a class which is a derived class – then it is referred to as multilevel inheritance.”
3 Give the sequence of Constructor/Destructor Invocation when object of class Result is created.
Try it, then show the answerAnswer
In the chapter’s multilevel inheritance example, class Result is derived from Exam, which is derived from Student. When a Result object is created, constructors run from the base class to the derived class.
- Student constructor: The constructor of the base class Student is invoked first.
- Exam constructor: Next, the constructor of Exam is invoked because Exam is derived from Student.
- Result constructor: Finally, the constructor of the derived class Result is invoked.
- Destructor order: When the Result object expires, destructors are invoked in reverse order: Result first, then Exam, and finally Student.
- Complete sequence: Thus, creation proceeds Student → Exam → Result, and destruction proceeds Result → Exam → Student.
Example: The chapter illustrates this order with a multilevel inheritance program: the base constructor runs before the derived constructors, and the derived destructors run before the base destructor.
Therefore, constructors run from base to derived, while destructors run from derived to base.
From the book: “The destructors are executed in the reverse order.”
7. Write the names of all member functions accessible from the object of class Result.
Try it, then show the answerAnswer
Rcalculate() and Rdisplay()
These functions are declared public in Result. The public members of Marks remain public when Marks is inherited publicly, but its inherited Personal members were made private in Marks.
From the book: “The accessibility of base class by the derived class is controlled by visibility modes.”