DELHI 2002
1.a. Illustrate the concept of Inheritance with the help of an example. 2
Ans: The capability of one class to inherit propertied from another class, is called as inheritance.
The most important advantage of inheritance is code reusability. There are 5 types of inheritance:
(i) Single Inheritance): When a sub class inherits only
from one base class, it is known as single inheritance.
(ii) Multiple Inheritance: When a sub class inherits from
multiple base classes, it is known as multiple inheritance.
(iii) Hierarchical Inheritance: When many sub classes
inherit from a single base class, it is known as hierarchical inheritance.
(iv) Multilevel Inheritance: When a subclass inherits
from a class that itself inherits from another class, it is known as multilevel inheritance.
(v) Hybrid Inheritance: Hybrid inheritance combines two or more forms of inheritance
2001
1.a. Reusability of classes is one of the major properties of OOP. How is it implemented in C++. 2
Ans: Resuability of classes can be implemented through Inheritance. Ie After developing a class, if you want a class which consists the features of this class( ie members ) and the other features also, then instead of developing a class which consists all these features, you can inherited the existing features (members) and you can develop new class consists the remaining features using
inheritance
(in Object Oriented Programming ie in C++.)
DELHI 2000
DELHI 2000
2.c. Consider the following and answer the questions given below:
class School
{
int A;
protected:
int B,C;
public:
void INPUT(int);
void OUTPUT(); };
class Dept:protected School
{
int X,Y; protected:
void IN(int,int) public:
void OUT();
};
class Teacher:public Dept
{
int P;
void DISPLAY(void);
public:
void ENTER();
};
(i) Name the base class and derived class of the class Dept.
Ans: Base class of Dept - School
Derived class of Dept - Teacher
(ii) Name the data member(s) that can be accessed from function OUT().
Ans: Dept::X Dept::Y
School::B
School::C