0% found this document useful (0 votes)
84 views2 pages

Unit III Extending Classes Inheritance Notes

msbte k scheme oop unit 3 notes

Uploaded by

patilaadesh04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views2 pages

Unit III Extending Classes Inheritance Notes

msbte k scheme oop unit 3 notes

Uploaded by

patilaadesh04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Unit III: Extending Classes Using Inheritance

3.1 Introduction to Inheritance

-------------------------------

- Inheritance allows a derived class to acquire properties of a base class.

- Syntax: class Derived : AccessSpecifier Base { };

- Visibility Modes:

* Public: Public and protected members remain the same.

* Protected: Public and protected members become protected.

* Private: Public and protected members become private.

3.2 Types of Inheritance

------------------------

- Single: A class inherits from one base class.

- Multilevel: A class inherits from a derived class.

- Multiple: A class inherits from multiple base classes.

- Hierarchical: Multiple classes inherit from a single base class.

- Hybrid: Combination of inheritance types.

3.3 Virtual Base Class, Abstract Class, Constructor in Derived Class

--------------------------------------------------------------------

- Virtual Base Class: Used to resolve ambiguity in multiple inheritance.

- Abstract Class: Contains at least one pure virtual function.

- Constructor in Derived Class: Calls base class constructor using initializer list.

Code Example for Multilevel Inheritance:


#include <iostream>

using namespace std;

class Base { public: int x; Base() { x = 10; } };

class Derived1 : public Base { public: int y; Derived1() { y = 20; } };

class Derived2 : public Derived1 { public: int z; Derived2() { z = 30; } };

int main() {

Derived2 obj;

cout << obj.x << obj.y << obj.z;

return 0;

You might also like