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.
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:
- This visibility mode is optimal i.e, when not used, the default visibility mode is private.
- 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.
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.
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.
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:
- public members of the base class become the public members of the derived class.
- Most used inheritance mode.
Private:
- This visibilities mode is optimal i.e., when not used, the default visibility mode is private.
- Private members are not inheritance by the derived class.
Question 3.
Mention any 2 advantages of inheritance?
Answer:
- Reusing existing code
- Faster development time
- Easy to maintain
- Easy to extend
- Memory utilization
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:
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:
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.
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:
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.
Question 14.
Explain single inheritance with a suitable C++ program.
Answer:
Question 15.
Explain multilevel inheritance with a suitable C++ program.
Answer:
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.
Question 17.
How does inheritance influence the working of constructors?
Answer:
- Constructors are used to initialize data members of an object.
- 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.
- Remember, we usually create objects to the derived class.
- Thus, the derived class passes arguments to the base class constructor.
- When both the derived & base class contain construtors, the base constructor is executed first & then the constructor in the derived class is executed.
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:
- Public members of the base class become the public members of the derived class.
- The private members of the base class can be accessed indirectly using public protected member functions the base class.
- This visibility mode is optimal. ex: When not used, the default visibility mode is private.
- 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.
- Private members are not inherited by the derived class.
Question 2.
What are the advantages of inheritance?
Answer:
- Reusing existing code
- Faster development time
- Easy to maintain
- Easy to extend
- Memory utilization
Question 3.
What are the types of inheritance?
Answer:
- Single Inheritance
- Multilevel Inheritance
- Multiple Inheritance
- Hierarchical Inheritance
- Hybrid 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:
- The public members of the base class become the public members of the derived class.
- The private members of the base class cannot be inheritance to the derived class.
- The protected members of the base stay protected in a derived class. Class subclass: public superclass.
(B) Private Inheritance:
- The public members of the base class become the private members of the derived class.
- The private members of the base class cannot be inheritance to the derived class.
- The protected members of the base stay protected in a derived class. Class subclass : private super class.
(C) Protected Inheritance:
- The public members of the base class become the protected member of the derived class.
- The private members of the base class cannot be inherited to the derived class.
- 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:
- Reusing existing code
- Faster development time
- Easy to maintain
- Easy to extend
- Memory utilization
Question 3.
What are the types of Inheritance? Explain any 2.
Answer:
- Single Inheritance
- Multilevel Inheritance
- Multiple Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
1. Single Inheritance:
If a class is derived from a single base class, it is called as single Inheritance.
ex:
2. Multilevel Inheritance:
The class are derived form the classes that are already derived is called multilevel Inheritance.
ex:
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 { -------- -------- };
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:
- Its constructor and its destructor.
- Its operator = () members
- Its friends.
Question 7.
Explain single inheritance with a suitable C++ program.
Answer:
{
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.
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.
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:
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.