Login    New User    Forgot Password    Help      

Types of Inheritance

GO TO INDEX

Types of Inheritance

There are five different inheritances supported in C++:

(1) Simple / Single
(2) Multilevel
(3) Hierarchical
(2) Multiple
(3) Hybrid
Inheritance

Example

#include <iostream>

class A

{

int data;

public: void f(int arg)

{ data = arg; }

int g()

{ return data; }

};

class B

{ public: A x; };

int main()

{

B obj;

obj.x.f(20);

cout << obj.x.g() << endl; //

cout << obj.g() << endl;

}

GO TO INDEX