Inheritance - Webs

24
YK 1 Inheritance Inheritance is the capability of a class (called derived class) to inherit the properties (data and functions) of another existing class (called base class). Inheritance is a way to implement reusability of the code which is a very important feature of Object Oriented Programming paradigm. Inheritance can be used wherever it is observed that a new class which is to be defined is a kind of another existing class with some additional features (data or function). E.g. 1. An automobile is a kind of vehicle. Therefore automobile class can be inherited/derived from vehicle class. 2. A shop is a kind of building. Therefore shop class can be inherited/derived from building class. Need for Inheritance: i) Closeness to real world ii) Reusability of the code iii) Transitive nature of Inheritance Example: # include <iostream.h> # include <conio.h> class counter { protected : unsigned int count; public : counter() { count = 0; } void inc_count() { count++; } int get_count() { return count; } }; class new_counter : public counter { public : void dec_count() { count--; } }; void main() { clrscr(); counter c1; new_counter c2; cout <<"\nc1 = "<<c1.get_count();

Transcript of Inheritance - Webs

Page 1: Inheritance - Webs

YK 1

Inheritance Inheritance is the capability of a class (called derived class) to inherit the properties (data and functions) of another existing class (called base class). Inheritance is a way to implement reusability of the code which is a very important feature of Object Oriented Programming paradigm. Inheritance can be used wherever it is observed that a new class which is to be defined is a kind of another existing class with some additional features (data or function). E.g.

1. An automobile is a kind of vehicle. Therefore automobile class can be inherited/derived from vehicle class.

2. A shop is a kind of building. Therefore shop class can be inherited/derived from building class.

Need for Inheritance: i) Closeness to real world ii) Reusability of the code iii) Transitive nature of Inheritance Example: # include <iostream.h> # include <conio.h>

class counter

{ protected :

unsigned int count;

public :

counter()

{ count = 0; }

void inc_count()

{ count++; }

int get_count()

{ return count; } };

class new_counter : public counter

{

public :

void dec_count() { count--; }

};

void main()

{

clrscr();

counter c1; new_counter c2;

cout <<"\nc1 = "<<c1.get_count();

Page 2: Inheritance - Webs

YK 2

cout <<"\nc2 = "<<c2.get_count();

c1.inc_count();

c2.inc_count(); c2.inc_count();

cout <<"\nc1 = "<<c1.get_count();

cout <<"\nc2 = "<<c2.get_count();

c2.dec_count();

// c1.dec_count(); Error cout <<"\nc1 = "<<c1.get_count();

cout <<"\nc2 = "<<c2.get_count();

}

Inheritance Mode: The inheritance mode (in the derived class specification) specifies how the members of base class will be accessible in derived class (publicly, privately, or protectedly). Inheritance mode can be public, private, or protected. The following table shows the effects of different visibility modes:

Inheritance mode Visibility Mode in Base Class

Visibility Mode in Derived Class

Public Public Public

Protected Protected

Private -

Protected Public Protected

Protected Protected

Private -

Private Public Private

Protected Private

Private -

Inheritance mode is also called access mode. The Base class private members are also inherited in the Derived class but they are not categorized in the visibility mode inside the derived class and so these members remains locked (i.e. cannot be accessed) in the derived class. Note: Base class Constructors and Destructor are not inherited by the derived class. Demo for inheritance modes:

#include <iostream.h>

#include <conio.h>

class A {

private:

int x;

void f1()

Page 3: Inheritance - Webs

YK 3

{ x=1; y=2; z=3; }

public:

int y;

void f2() { x=1; y=2; z=3;}

protected:

int z;

void f3()

{ x=1; y=2; z=3;}

}; /*Irrespective of the access types the members are

accessible within the class*/

class B : public A

{

private:

int p;

void w1()

{ p=4; q=5; r=6;

y=2; // *1

z=3; // *1

f2();// *1 f3();// *1

}

public:

int q; // *1 y , f2()

void w2()

{ p=4; q=5; r=6;

y=2; // *1

z=3; // *1

f2();// *1

f3();// *1

}

protected: int r; // *1 z , f3()

void w3()

{ p=4; q=5; r=6;

y=2; // *1

z=3; // *1

f2();// *1

f3();// *1

}

};

/* *1 - in addition to it's own members , the inherited members ( y , z, f2() , f3() ) in the derived class follow the laws of visibility modes. */

/*Since class B is inherited from class A , therefore all the members of class A are inherited in class B. The inheritance mode is public, therefore:

Page 4: Inheritance - Webs

YK 4

1. the private members of class A inherited in class B are not categorized under any visibility mode which means that by no way these members are accessible in class B.

2. the public and protected members of class A inherited in class B are categorized under public and protected visibility modes of class B respectively. In other words public members of class A remain public in class B and protected members of class A remains protected in class B.

*/ class C : private A

{ private:

int p; // *2 y , f2() , z , f3() void w1()

{ p=4; q=5; r=6;

y=2; // *2

z=3; // *2

cout<<"\np="<<p;

cout<<"\nq="<<q;

cout<<"\n r="<<r; f2();// *2

f3();// *2

}

public:

int q;

void w2() { p=4; q=5; r=6;

y=2; // *2

z=3; // *2

cout<<"\np="<<p;

cout<<"\nq="<<q;

cout<<"\n r="<<r;

f2();// *2

f3();// *2

}

protected:

int r;

void w3() { p=4; q=5; r=6;

y=2; // *2

z=3; // *2

cout<<"\np="<<p;

cout<<"\nq="<<q;

cout<<"\nr="<<r;

f2();// *2

f3();// *2

}

};

/* Since class C is inherited from class A , therefore all the members of class A are inherited in class C. The inheritance mode is private, therefore the public and

Page 5: Inheritance - Webs

YK 5

protected inherited members of class A are categorized under private visibility mode of class C. Therefore, we can say that private inheritance mode does not promote further inheritance because the inherited members in class C lie under private visibility mode */

class D : protected A

{

private:

int p;

void w1() { p=4; q=5; r=6;

y=2; // *3

z=3; // *3

f2(); // *3

f3(); // *3

cout<<"\np="<<p; cout<<"\nq="<<q;

cout<<"\n r="<<r;

}

public:

int q;

void w2() { p=4; q=5; r=6;

y=2; // *3

z=3; // *3

f2(); // *3

f3(); // *3

cout<<"\np="<<p;

cout<<"\nq="<<q; cout<<"\n r="<<r;

}

protected:

int r; // *3 y , f2() , z , f3()

void w3()

{ p=4; q=5; r=6; y=2; // *3

z=3; // *3

f2(); // *3

f3(); // *3

cout<<"\np="<<p;

cout<<"\nq="<<q; cout<<"\nr="<< r;

}

};

/* Since class D is inherited from class A , therefore all the members of class A are inherited in class D. The inheritance mode is protected, therefore the public and protected members of class A inherited in class D are categorized under protected visibility mode of class D. Therefore, we can say that protected inheritance mode promotes further inheritance keeping the concept of data hiding intact because the inherited members in class D lie under protected visibility mode */

Page 6: Inheritance - Webs

YK 6

void main() { clrscr(); A a1; a1.y=2; a1.f2(); B b1; b1.q=5; // accessible since q , w2() are under public access type b1.w2(); b1.y=5; // accessible since y , f2() has got inherited under public access type b1.f2(); C c1; c1.q=5; // accessible since q , w2() are under public access type c1.w2(); D d1; d1.q=5; // accessible since q , w2() are under public access type d1.w2(); }

Visibility mode Accessible from Own class Derived class Outside the class

Public Yes Yes Yes

Protected Yes yes No

Private Yes No No

Exercises:

1. Create a class student with data members name, class, section, roll No. and function members getdata(), printdata(), and promote(). From this class derive a class 'Sr_std' with additional data member stream. Also include another function member change_stream().

Derived class constructors: If the derived class has no constructor, the compiler substitutes a no-argument constructor from the base class, but it draws a line at more complex constructors. To make such a definition work, we must write a new set of constructors for the derived class. # include <iostream.h> # include <conio.h> class counter { protected : unsigned int count; public :

Page 7: Inheritance - Webs

YK 7

counter() { count = 0; }

counter (int c) { count = c; }

void inc_count()

{ count++; } int get_count()

{ return count; } }; class new_counter : public counter { public :

new_counter() : counter() {}

new_counter(int c) : counter(c) {}

void dec_count() { count--; }

}; void main() { clrscr(); new_counter c1; new_counter c2(100); cout <<"\nc1 = "<<c1.get_count(); cout <<"\nc2 = "<<c2.get_count(); c1.inc_count(); c2.inc_count(); c2.inc_count(); cout <<"\nc1 = "<<c1.get_count(); cout <<"\nc2 = "<<c2.get_count(); c2.dec_count(); c1.dec_count(); Error cout <<"\nc1 = "<<c1.get_count(); cout <<"\nc2 = "<<c2.get_count(); } In the above program, when the statement new_counter c1; is executed the compiler will create an object of type new_counter and then calls the counter() constructor, which carries out the work. The new_counter() constructor could also add additional statement(s) of its own.

Page 8: Inheritance - Webs

YK 8

The statement new_counter c2(100); calls the constructor new_counter (int c);. This constructor also calls the corresponding constructor in the base class. Sequence of Constructor and Destructor Call and Execution: When an object of a derived class is created, a call to its constructor is made. Before executing any statement in the constructor body, a call to its base class constructor is made. If the base class is again a derived class, a call to its base class constructor is made. This sequence continues until a constructor of a non-derived class is called. Then the computer starts executing these constructors in the normal way. It means that if an object of a derived class is created then its base class constructor will be executed first and then the derived class constructor. For example consider a class D derived from a class C which is derived from B which again is derived from A. If an object of class D is created then constructor call will be in the sequence D() � C()� B()� A(). The constructor execution will be in the sequence A()� B()� C()� D(). If an object of class B is created then the constructor call will be in the sequence B()� A(). The constructor execution will be in the sequence A()� B(). When the scope of a derived class object gets over, its destructor is called. After executing the statements in the destructor body a call to the base class destructor is made. This base class destructor is then executed. Same thing happens if the base class is again a derived class. For example consider a class D derived from a class C which is derived from B which again is derived from A. If the scope of an object of class D gets over then the destructor call will be in the sequence D()� C()� B()� A(). The destructor execution will also be in the sequence D()� C()� B()� A(). (Compare it with the constructor call and execution sequence) If an object of class B is created then the constructor call will be in the sequence B()� A(). The constructor execution will be in the sequence B()� A(). Overriding Member Functions: When the same function exists in both the base class and the derived class, the function in the derived class will be executed by default by the objects of the derived class. We say that derived class members override the base class members. So to get the base class member executed scope resolution operator has to be specified. Abstract base Class: Classes used only for deriving other classes are called Abstract Classes, meaning that no actual instances (objects) of this class are created. Types of Inheritance:

• Multi level Inheritance

Page 9: Inheritance - Webs

YK 9

• Multiple Inheritance

• Hierarchical Inheritance Multi level Inheritance It is a type of inheritance where one derived class acts as the base class of another derived class.

1st inheritance: Base class: ClassA

Derived class: ClassB 2nd inheritance Base class: ClassB

Derived class: ClassC

Demo: #include <iostream.h>

#include <conio.h>

class base

{

private:

int x;

float y;

public:

base() {}

base(int p,float q)

{ x=p; y=q;

cout<<"\nbase CC";

} void show()

{ cout<<"\nbase x="<<x;

cout<<"\nbase y="<<y;

}

~base()

{ cout<<"\nbase DC"; }

};

class der1 : public base

{ private:

int x;

ClassA

ClassB

ClassC

Page 10: Inheritance - Webs

YK 10

float y;

public:

der1(int p,float q,int m,float n):base(m,n)

{ x=p; y=q; cout<<"\nder1 CC";

}

void show()

{ cout<<"\nder 1 x="<<x;

cout<<"\nder 1 y="<<y;

} ~der1()

{ cout<<"\nder1 DC"; }

};

class der2 : public der1

{

private:

int x;

float y;

public:

der2(int p,float q,int m,float n,int a,float

b): base(m,n,a,b)

{ x=p; y=q; cout<<"\nder2 CC";

}

void show()

{ cout<<"\nder2 x="<<x;

cout<<"\nder2 y="<<y;

}

~der2()

{ cout<<"\nder2 DC"; }

};

void main()

{ clrscr(); der2 d2(1,1.5,2,2.5,3,3.5);

d2.show();

d2.der1::show();

d2.base::show();

getch();

}

Use of scope resolution operator in inheritance

#include <iostream.h>

class base { public: int i;

};

// derived1 inherits base.

class derived1 : public base

Page 11: Inheritance - Webs

YK 11

{ public: int j;

};

// derived2 inherits base. class derived2 : public base

{ public: int k;

};

/* derived3 inherits both derived1 and derived2. This means

that there are two copies of base in derived3! */ class derived3 : public derived1, public derived2

{ public: int sum;

};

void main()

{derived3 ob;

ob.derived1::i = 10; // scope resolved, use derived1's i

ob.j = 20;

ob.k = 30;

// scope resolved

ob.sum = ob.derived1::i + ob.j + ob.k;

// also resolved here

cout << ob.derived1::i << " "; cout << ob.j << " " << ob.k << " ";

cout << ob.sum;

}

Hierarchical Inheritance

It is a type of inheritance where more than one classes are derived from one class. That is where there is only one base class and more than one derived classes.

Base class: ClassA Derived classes: ClassC and ClassB

Example: #include <iostream.h>

#include <conio.h>

class base

{ private:

int x;

ClassA

ClassB ClassC

Page 12: Inheritance - Webs

YK 12

float y;

public:

base() {}

base(int p,float q) { x=p; y=q;

cout<<"\nbase CC";

}

void show()

{ cout<<"\nbase x="<<x;

cout<<"\nbase y="<<y; }

~base()

{ cout<<"\nbase DC"; }

};

class der1 : public base

{ private:

int x;

float y;

public:

der1(int p,float q)

{ x=p; y=q;

cout<<"\nder1 CC"; }

void show()

{ cout<<"\nder 1 x="<<x;

cout<<"\nder 1 y="<<y;

}

~der1()

{ cout<<"\nder1 DC"; }

};

class der2 : public base

{ private:

int x;

float y; public:

der2(int p,float q,int m,float n):base(m,n)

{ x=p; y=q;

cout<<"\nder2 CC";

}

void show()

{ cout<<"\nder2 x="<<x;

cout<<"\nder2 y="<<y;

}

~der2()

{ cout<<"\nder2 DC"; }

};

void main()

{ clrscr();

der1 d1(1,1.5);

d1.show();

Page 13: Inheritance - Webs

YK 13

d1.base::show();

der2 d2(11,11.5,12,12.5);

d2.show();

d2.base::show(); getch();

}

Multiple Inheritance

It is a type of inheritance where a class is derived from more than on classes. That is where there are more than one base classes and one derived class.

Base classes : ClassA and ClassB

Derived class: ClassC Example:

#include <iostream.h>

#include <conio.h> class base1

{ private:

int x;

float y;

public:

base1(int p,float q)

{ x=p; y=q;

cout<<"\nbase1 CC";

}

void showval()

{ cout<<"\nbase 1 x="<<x;

cout<<"\nbase 1 y="<<y;

} ~base1()

{ cout<<"\nbase1 DC"; }

};

class base2

{ private:

int x;

float y;

public:

base2(int p,float q)

ClassA ClassB

ClassC

Page 14: Inheritance - Webs

YK 14

{ x=p; y=q;

cout<<"\nbase2 CC";

}

void showval() { cout<<"\nbase 2 x="<<x;

cout<<"\nbase 2 y="<<y;

}

~base2()

{ cout<<"\nbase2 DC"; }

};

class der : public base1,public base2

{ private:

int x;

float y;

public:

der(int p,float q,int m,float n,int a,float

b):base1(m,n),base2(a,b)

{

x=p; y=q;

cout<<"\nder CC";

}

void show() { cout<<"\nder x="<<x;

cout<<"\nder y="<<y;

}

~der()

{ cout<<"\nder DC"; }

};

void main()

{ clrscr();

der d(1,1.5,2,2.5,3,3.5);

d.show();

// d.showval(); Error because of ambiguity

d.base1::showval(); d.base2::showval();

getch();

}

Containership: Containership is the concept of having one or more object(s) of one or more class(es)as data member(s) of another class. Containership implements has a relationship. //CNTNRSHP.CPP //Triangle contains Points #include <iostream.h> #include <conio.h> #include <math.h>

Page 15: Inheritance - Webs

YK 15

class POINT { int x, y; public: POINT() { x = y = 0;} void get_point() { cout<<"\nEnter abscissa: "; cin>>x; cout<<"Enter ordinate: "; cin>>y; } void show_point() { cout<<"("<<x<<", "<<y<<")";} float distance() { float d = (x*x)+(y*y); return sqrt(d); } float distance(POINT P) { float d = (P.x-x)*(P.x-x)+(P.y-y)*(P.y-y); return sqrt(d); } float slope(POINT P) { float s = float (P.y-y)/(P.x-x); return s; } void equation(POINT P) { float m = slope(P); float c = -m*x+y; cout<<"y = "<<m<<"x "; if (c > 0) cout<<"+ "<<c; else if (c < 0) cout<<c; } }; class TRIANGLE { POINT A, B, C; //Containership public: TRIANGLE() { get_vertices(); } void get_vertices() { cout<<"\nEnter coordinates of the vertices of triangle: "; cout<<"\nFirst vertex: "; A.get_point();

Page 16: Inheritance - Webs

YK 16

cout<<"\nSecond vertex: "; B.get_point(); cout<<"\nThird vertex: "; C.get_point(); } void show_vertices() { cout<<"\nCoordinates of the vertices of triangle are: "; A.show_point(); cout<<", "; B.show_point(); cout<<", and "; C.show_point(); cout<<"\n"; } float Area() { float a = B.distance(C), b = C.distance(A), c = A.distance(B); float s = (a+b+c)/2; float A = s*(s-a)*(s-b)*(s-c); return sqrt(A); } }; void main() { clrscr(); TRIANGLE T1; T1.show_vertices(); cout<<"\nArea of the triangle is: "<<T1.Area()<<" sq. units"; getch(); } Difference between inheritance and containership Inheritance implements is a kind of relationship whereas containership implements has a relationship. Demo:

//file name “add.h” – this is a header file class address { int stno; char city[10]; long pcode; public: void geta() { cout<<"\nEnter street number : "; cin>>stno; cout<<"\nEnter city name : "; cin>>city; cout<<"\nEnter pin code : "; cin>>pcode;

Page 17: Inheritance - Webs

YK 17

} void dispa() { cout<<"\nSt no="<<stno; cout<<"\nCity Name="<<city; cout<<"\nPin code ="<<pcode; }

}; //file name “stud.h” – this is a header file class student { int roll; char name[20]; public: void get() { cout<<"\nEnter roll : "; cin>>roll; cout<<"\nEnter name : "; cin>>name; } void disp() { cout<<"\nRoll="<<roll; cout<<"\nName="<<name; } }; //The program showing the difference between containership and inheritance #include <iostream.h> #include <conio.h> #include "add.h" #include "stud.h" class employee:public student { int empid; float sal; address a; public: void getdata() { get(); a.geta(); cout<<"\nEnter empid: "; cin>>empid; cout<<"\nEnter salary : "; cin>>sal; } void display() { disp(); a.dispa(); cout<<"\nempid: "<<empid; cout<<"\nsalary: "<<sal; }

Page 18: Inheritance - Webs

YK 18

}; void main() { clrscr(); employee e; e.getdata(); e.display(); getch(); }

Note: You must execute all given programs for better understanding of the concepts discussed in this chapter.

Page 19: Inheritance - Webs

YK 19

Exercises 1. Inheritance is a way to

a. make general classes into more specific classes. b. pass arguments to objects of classes. c. add features to existing classes. d. improve data hiding and encapsulation.

2. Advantages of inheritance include

a. providing class growth through natural selection. b. facilitating class libraries. c. avoiding rewriting code. d. providing useful conceptual framework.

3. The scope-resolution operator usually

a. limits the visibility of variables to a certain function. b. tells what base class a class is derived from. c. specifies a particular class. d. resolves ambiguities.

4. A class hierarchy

a. shows the same relationships as an organisation chart b. describes "has a" relationships c. describes "is a kind of" relationships d. shows the same relationships as a family tree

5. Assume that a class Derv is privately derived from a class Base. An object of

class Derv located in main() can access a. Public member of Derv b. Protected members of Derv c. Private members of Derv d. Public members of Base e. Protected members of Base f. Private members of Base

6. True or False : A class D can be derived from a class C, which is derived from

a class B, which is derived from a class A.

7. True or False: It is useful to sometimes specify a class from which no objects will ever be created.

8. True or false : Adding a derived class to a base class requires fundamental

changes to the base class.

9. True or false: If no constructors are specified for a derived class , objects of the derived class will use the constructors in the base class.

10. True or False : It is illegal to make objects of one class member of another

class.

11. A "child" class is said to be ______________________ from a base class.

Page 20: Inheritance - Webs

YK 20

12. To be accessed from a member function of the derived class, data or functions in the base class must be public or _____________.

13. Assume there is a class derv that is derived from a base class base. Write the declarator for a derived class constructor that takes one argument and passes this argument along to the constructor in the base class.

14. If a base class contains a member function basefunc(), and a derived class

does not contain a function with this name, can an object of the derived class access basefunc()?

15. Write the first line of the specifier for a class Bosworth that is publicly

derived from a class Alphanso.

16. Assume the classes mentioned in 15th Qs and that class Alphanso contains a member function called alfunc(). Write a statement that allows object BosworthObj of class Bosworth to access alfunc().

17. Write a declarator for a no arguement constructor of the derived class

Bosworth of the 15th Qs that calls a no arguement constructor in the base class Alphanso.

18. If a base class and a derived class each include a member function with the

same name , which member function will be called by an object of the derived class, assuming the scope resolution operator is not used.

19. Write the first line of a specifier for a class Tyre that is derived from class

wheel and from class Rubber.

20. Assume a class Derv derived from a base class Base. Both classes contain a member function func() that takes no arguements. Write a statement to go in a member function of Derv that calls func() in the base class.

21. What is the difference between protected and private members?

22. How do default constructors and destructors behave in an inheritance hierarchy?

23. What is an abstract base class?

24. What is polymorphism?

25. What is wrong in the following definitions:

class X { protected: int a; }; class Y : publix X

Page 21: Inheritance - Webs

YK 21

{ public: void set(X x, int c) { x.a = c; } };

26. Consider the following class declaration and answer the questions:

class Mydata { protected: int data; public: void get_mydata(int); void manip_data(int); void show_data(int); }; void mydata1 : private Mydata { protected: int data1; public: void get_mydata1(int); void show_data(int); }; void person : public mydata1 { public: void show_data2() }; 1. Name all the base classes and their derived classes. 2. Name data and functions inherited by class person. 3. Name the data and function members which can be accessed by the

objects of class 'person'. 4. Name the class(es) in which data1 can be accessed.

27. Consider the following class declaration and answer the questions:

class zoo { char location[20]; protected: int no_of_animals; public: void inputdata(char, int); void outputdata(); }; class animal : protected zoo { int tail; protected: int legs; public: void readdata(int, int); void writedata();

Page 22: Inheritance - Webs

YK 22

}; class carnivorous:private animal { int paw_size; public: void fetchdata(int); void displayed(); }; 1. Name the base class and the derived class of the class animal. 2. Name the data member(s) that can be accessed from function

displaydata(). 3. Name the data member(s) that can be accessed by an object of

carnivorous class. 4. Is the member function outputdata() accessible to the objects of animal

class? 28. Consider the following declarations and answer the questions given below:

class PPP { int H; protected: int S; public: void INPUT(int); void OUT(); }; class QQQ:private PPP { int T; protected: int U; public: void INDATA(int, int); void OUTDATA(); }; class RRR: public QQQ { int M; public: void DISP(void); }; 1. Name the base class and the derived class of the class QQQ. 2. Name the data member(s) that can be accessed from function DISP(). 3. Name the data member(s) that can be accessed by an object of RRR class. 4. Is the member function OUT() accessible to the objects of QQQ class?

29. Consider the following C++ declarations and answer the questions given below: class A { void anyval(); protected: int x,y;

Page 23: Inheritance - Webs

YK 23

int procval(); public: void getvalA(); void putvalA(); }; class B: protected A { int a,b; protected: int c,d; void getvalB(); public: void putvalB(); }; class c: private B { int p; protected: int q; void getval(); public: void showval(); }; 1. Name all the function members which are accessible by the objects of

class C. 2. Name all the protected members of class B. 3. Name the base class and the derived class of class B. 4. Name the data members which are accessible from member functions

of class C.

30. 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();

Page 24: Inheritance - Webs

YK 24

}; 1. Name the base class and the derived class of the class Dept. 2. Name the data members that can be accessed from functio OUT(). 3. Name the private member function(s) of the class Teacher. 4. Is the member function OUT() accessible by the objects of Dept?