2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Students can Download 2nd PUC Computer Science Chapter 10 Inheritance Questions and Answers, Notes Pdf, 2nd PUC Computer Science Question Bank with Answers helps you to revise the complete Karnataka State Board Syllabus and to clear all their doubts, score well in final exams.

Karnataka 2nd PUC Computer Science Question Bank Chapter 10 Inheritance

2nd PUC Computer Science Inheritance One Mark Questions and Answers

Question 1.
What is inheritance?
Answer:
Inheritance is the capability of one class to inherit the properties from another class.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 2.
How to implement inheritance?
Answer:
Inheritance can be implemented by creating new classes. Reusing the properties of existing one.

Question 3.
What is base class?
Answer:
It is the class whose properties are inherited by another class.

Question 4.
What is derived class?
Answer:
It is the class that inherits the properties from base class.

Question 5.
What is public access specifier?
Answer:
Public members of the base class become the public members of the derived class.

Question 6.
What is the private access specifier?
Answer:

  1. This visibility mode is optimal i.e, when not used, the default visibility mode is private.
  2. Private members are not inherited by the derived class.

Question 7.
Mention any are advantage of inheritance?
Answer:
Reuse of existing code.

Question 8.
Is inheritance possible in c?
Answer:
No.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 9.
What is the use of protected access specifier?
Answer:
Protected member of base class stay protected in derived class.

Question 10.
What is the use of public access specifier?
Answer:
Public members can be accessed inside as well as outside the class definition.

Question 11.
What is the use of private access specifier?
Answer:
Private members are accessible only to member function within a class only.

Question 12.
What is single inheritance?
Answer:
If a class is derived from a single base class, it is called as single inheritance.

Question 13.
What is multilevel inheritance?
Answer:
The classes are derived from the classes that are already derived is called multilevel inheritance.

Question 14.
What is hierarchical inheritance?
Answer:
If a number of classes are derived from a single base, it is called as hierarchical inheritence.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 15.
What is hybrid inheritance?
Answer:
Hybrid inheritance is combination of Hierarchical & Multilevel Inheritance.

Question 16.
What is multiple inheritance?
Answer:
If a class is derived from more than one base class, if known as multiple inheritance.

Question 17.
What is virtual base class?
Answer:
When two or more object are derived from a common base class, we can prevent multiple copied from the base class or virtual when it is being inherited. Such a base class is known as virtual base class.

Question 18.
What is an abstract class?
Answer:
An abstract class is one that is not used to create objects.

Question 19.
When we need to inherit?
Answer:
Suppose x is a class already defined & we need to redefine another class y having same properties of class x, we need to inherit the properties of class x to class y in this situation.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 20.
When is it necessary to use inheritance?
Answer:
Inheritance is necessary, suppose x is a class already defined & we need to redefine another classy having same properties of class x.

Question 21.
What is the visibility mode?
Answer:
The visibility mode basically controls the access specifiers to be for, inheritable members of base class in the derived class.

2nd PUC Computer Science Inheritance Two Marks Questions and Answers

Question 1.
How to implement inheritance?
Answer:
Inheritance is implemented by single, multilevel, multiple hierarchical & hybrid inheritance.

Question 2.
What is the difference between public & private access specifiers?
Answer:
Public:

  1. public members of the base class become the public members of the derived class.
  2. Most used inheritance mode.

Private:

  1. This visibilities mode is optimal i.e., when not used, the default visibility mode is private.
  2. Private members are not inheritance by the derived class.

Question 3.
Mention any 2 advantages of inheritance?
Answer:

  1. Reusing existing code
  2. Faster development time
  3. Easy to maintain
  4. Easy to extend
  5. Memory utilization

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 4.
Mention any 2 types of inheritance?
Answer:

  • Multiple inheritances
  • Multilevel inheritance.

Question 5.
What is the difference between inheritance & polymorphism?
Answer:
Object & Class:
The ability of an operator & function to take multiple forms is known as polymorphism.

Question 6.
What is single inheritance? Given an example.
Answer:
If a class is derived from a single base class, it is called as single inheritance.
Ex:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 1

Question 7.
What is multilevel inheritance? Give an example.
Answer:
The classes are derived from the classes that are already derived is called multilevel inheritance.
Ex:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 2

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 8.
What is hierarchical inheritance? Give an example.
Answer:
If a number of class are derived from a single base class, it is called as hierarchical inheritance.
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 3

Question 9.
What is hybrid inheritance? Given example.
Answer:
Hybrid inheritance is a combination of Hierarchical & multilevel Inheritance

Question 10.
What is multiple inheritances? Given an example.
Answer:
If a class is derived from more than one base class, it is known as multiple inheritances.
Example:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 4

Question 11.
What is virtual base class? Give an example.
Answer:
When two or more objects are derived from a common base class, we can prevent multiple copied from the base class being present in an object by declaring the base class as virtual when it is being inherited, such a base class is known as virtual base class.
ex:

class A
{
-----------
-----------
};
class B: virtual public A
{
---------
---------
};
class C : virtual public A
{
--------
--------
};
class D: public B, public C
{
--------
--------
};

Question 12.
What is an abstract class?
Answer:
An abstract class is one that is not used to create objects.

Question 13.
Which are the components which can not be inherited?
Answer:
The private data members of a base class cannot be inherited.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 14.
Explain single inheritance with a suitable C++ program.
Answer:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 5
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 6

Question 15.
Explain multilevel inheritance with a suitable C++ program.
Answer:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 7
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 8
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 9

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 16.
Explain multiple Inheritance with a suitable C++ program.
Answer:
If a class is derived from more than one base, is known as multiple inheritance.
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 10
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 11
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 12
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 13

Question 17.
How does inheritance influence the working of constructors?
Answer:

  1. Constructors are used to initialize data members of an object.
  2. If any base class contains a constructor with one or more arguments, them it is mandatory for the derived class to have a constructor & pass the arguments to the base class constructor.
  3. Remember, we usually create objects to the derived class.
  4. Thus, the derived class passes arguments to the base class constructor.
  5. When both the derived & base class contain construtors, the base constructor is executed first & then the constructor in the derived class is executed.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 18.
How does inheritance influence the working of destructors?
Answer:
If the constructors are called down the line from the base to the derived class, the destructors are called Just in the reverse order. That is from the derived class up to the base class.

2nd PUC Computer Science Inheritance Three Marks Questions and Answers

Question 1.
What is the difference between public & private access specifier?
Answer:

  1. Public members of the base class become the public members of the derived class.
  2. The private members of the base class can be accessed indirectly using public protected member functions the base class.
  3. This visibility mode is optimal. ex: When not used, the default visibility mode is private.
  4. Public members of the base class become the private members of the derived class. Therefore, the public members of the base class can be accessed only by the member functions of the derived class & not by the objects of the derived class.
  5. Private members are not inherited by the derived class.

Question 2.
What are the advantages of inheritance?
Answer:

  1. Reusing existing code
  2. Faster development time
  3. Easy to maintain
  4. Easy to extend
  5. Memory utilization

Question 3.
What are the types of inheritance?
Answer:

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
  5. Hybrid Inheritance

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 4.
What is the difference between inheritance & polymorphism?
Answer:
Inheritance allows user to create a new class from a existing class. Polymorphism is the ability to exist in more than one form. An operation may exhibit different behavior in different instances.

2nd PUC Computer Science Inheritance Five Marks Questions and Answers

Question 1.
What is the difference berween public, private & protected inheritance?
Answer:
(A) Public Inheritance:

  1. The public members of the base class become the public members of the derived class.
  2. The private members of the base class cannot be inheritance to the derived class.
  3. The protected members of the base stay protected in a derived class. Class subclass: public superclass.

(B) Private Inheritance:

  1. The public members of the base class become the private members of the derived class.
  2. The private members of the base class cannot be inheritance to the derived class.
  3. The protected members of the base stay protected in a derived class. Class subclass : private super class.

(C) Protected Inheritance:

  1. The public members of the base class become the protected member of the derived class.
  2. The private members of the base class cannot be inherited to the derived class.
  3. The protected members of the base class stay protected in derived class. Class subclass : protected superclass.

Question 2.
What are the advantages of Inheritance?
Answer:

  1. Reusing existing code
  2. Faster development time
  3. Easy to maintain
  4. Easy to extend
  5. Memory utilization

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 3.
What are the types of Inheritance? Explain any 2.
Answer:

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
  5. Hybrid Inheritance

1. Single Inheritance:
If a class is derived from a single base class, it is called as single Inheritance.
ex:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 14

2. Multilevel Inheritance:
The class are derived form the classes that are already derived is called multilevel Inheritance.
ex:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 15

Question 4.
What is virtual base class? Give example.
Answer:
When two or more objects are derived from a common base class, we can prevent multiple copied from the base class being present in an object by declaring the base class as virtual when when it is being inherited. Such a base class is known as virtual base class.
ex:

class A
{
-----------
-----------
};
class B: virtual public A
{
---------
---------
};
class C: virtual public A
{
--------
--------
};
class D: public B, public C
{
--------
--------
};

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 5.
What is an abstract class?
Answer:
An abstract class is one that is not used to create objects.

Question 6.
Which are the components which cannot be inherited?
Answer:
The components which cannot be inherited:

  1. Its constructor and its destructor.
  2. Its operator = () members
  3. Its friends.

Question 7.
Explain single inheritance with a suitable C++ program.
Answer:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 16
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 17
{
XYZ ob;
Clrscr () ;
ob. read ();
ob. read 1 ();
ob. display ();
ob. display 1 ();
getch ();
}

Question 8.
Explain the requirements of a virtual base class.
Answer:
Consider the situation where the program design would require one base class (call it A) & two derived classes namely B & C, which are inherited from the base class A. Further, derived class D is created from B & C. In the public inheritance, B & C inherit one copy of the base class data, where as derived class D inherited from B & C gets two copies of base class data.

Now suppose a member function of D now wants to access the data members of the base class an ambiguity problem of which of the two copies is to access will be encountered. The compiler will generate error message for this ambiguity. To over come this problem. The derived class B & C should be declared as virtual.

2nd PUC Computer Science Question Bank Chapter 10 Inheritance

Question 9.
What is the visibility mode? What is its role.
Answer:
The visibility mode (private, public & protected) in the definition of the derived class specifies whether features of the base class are privately derived or publicly derived or protectedly derived. The visibility mode basically controls the access specifies to be for inheritanceble member of base class in the derived class.
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 18

Question 10.
How does inheritance influence the working of constructors & destructors?
Answer:
In Inheritance, usually objects are created using derived class. Thus if base class contains a constructor, then it is mandatory for derived class to have the constructor & pass the arguments to base class constructor. When both base & derived class contain constructors, the base constructor is executed. Incase of multiple & multilevel inheritance, the constructor will be executed in the order of inheritance.
ex:
2nd PUC Computer Science Question Bank Chapter 10 Inheritance 19
Deconstructor:
If the constructors are called down the line from the base to the derived class, the destructors are called just in the reverse order. That is from the derived class up to the base class.