SlideShare a Scribd company logo
oop database doc for studevsgdy fdsyn hdf
INHERITANCE
οƒ˜ Inheritance:
οƒΌ The capability of a class to derive properties and characteristics from another
class is called Inheritance
οƒΌ .Inheritance is one of the most important features of Object-Oriented
Programming.
οƒΌ Inheritance is a feature or a process in which, new classes are created from
the existing classes.
οƒΌ The new class created is called β€œderived class” or β€œchild class” and the existing
class is known as the β€œbase class” or β€œparent class”. T
οƒ˜ Syntax:
class <derived_class_name> : <access-specifier> <base_class_name>
{
//body
}
οƒ˜ EXAMPLE:
#include<iostream>
using namespace std;
class Person
{
int id;
char name[100];
public:
void set_p();
void display_p();
};
void Person::set_p()
{
cout<<"Enter the Id:";
cin>>id;
cout<<"Enter the Name:";
cin>>name;
}
void Person::display_p()
{
cout<<endl<<"id: "<< id<<"nName: "<<name;
}
class Student: private Person
{
char course[50];
int fee;
public:
void set_s();
void display_s();
};
void Student::set_s()
{
set_p();
cout<<"Enter the Course Name:";
cin>>course;
cout<<"Enter the Course Fee:";
cin>>fee;
}
void Student::display_s()
{
display_p();
cout<<"nCourse: "<<course<<"nFee: "<<fee<<endl;
}
int main()
{
Student s;
s.set_s();
s.display_s();
return 0;
}
οƒ˜ Modes of Inheritance:
There are 3 modes of inheritance.
1. Public Mode: If we derive a subclass from a public base class. Then the
public member of the base class will become public in the derived class and
protected members of the base class will become protected in the derived
class.
2. Protected Mode: If we derive a subclass from a Protected base class. Then
both public members and protected members of the base class will become
protected in the derived class.
3. Private Mode: If we derive a subclass from a Private base class. Then both
public members and protected members of the base class will become Private
in the derived class.
Types Of Inheritance:-
1. Single inheritance
2. Multilevel inheritance
3. Multiple inheritance
4. Hierarchical inheritance
5. Hybrid inheritance
οƒ˜ Single Inheritance: In single inheritance, a class is allowed to inherit from
only one class. i.e. one subclass is inherited by one base class only.
οƒ˜ Syntax:
class subclass_name : access_mode base_class
{
// body of subclass
};
OR
class A
{
... .. ...
};
class B: public A
{
... .. ...
};
ο‚· Multiple Inheritance: Multiple Inheritance is a feature of C++ where a
class can inherit from more than one class. i.e one subclass is inherited from
more than one base class.
οƒ˜ Syntax:
class subclass_name : access_mode base_class1, access_mode base_class2,
....
{
// body of subclass
};
class B
{
... ..
};
class C
{
... .. ...
};
class A: public B, public C
{
... ... ...
};
οƒ˜ Multilevel Inheritance: In this type of inheritance, a derived class is created
from another derived class.
οƒ˜ Syntax:
class C
{
... .. ...
};
class B:public C
{
... .. ...
};
class A: public B
{
... ... ...
};
οƒ˜ Hierarchical Inheritance: In this type of inheritance, more than one
subclass is inherited from a single base class. i.e. more than one derived class
is created from a single base class.
ο‚· Syntax:-
class A
{
// body of the class A.
}
class B : public A
{
// body of class B.
}
class C : public A
{
// body of class C.
}
class D : public A
{
// body of class D.
}
. Hybrid (Virtual) Inheritance: Hybrid Inheritance is implemented by
combining more than one type of inheritance. For example: Combining Hierarchical
inheritance and Multiple Inheritance.
οƒ˜ Why we use inheritance?
We use inheritance in C++ when both the classes in the program have
the same logical domain and when we want the class to use the
properties of its superclass along with its properties.

More Related Content

PPTX
Inheritance
PPTX
Inheritance
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
PDF
Inheritance
PPTX
Introduction to inheritance and different types of inheritance
PPT
Inheritance.ppt
PPTX
Inheritance
PDF
INHERITANCE
Inheritance
Inheritance
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
Inheritance
Introduction to inheritance and different types of inheritance
Inheritance.ppt
Inheritance
INHERITANCE

Similar to oop database doc for studevsgdy fdsyn hdf (20)

PPTX
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
PPTX
Inheritance in c++
PDF
inheritance-16031525566nbhij56604452.pdf
PPSX
Inheritance and Polymorphism in Oops
PPTX
Inheritance in C++ (Programming Fundamentals)
Β 
PDF
lecture 6.pdf
PPTX
Inheritance in c++ by Manan Pasricha
PPTX
Inheritance
PPTX
Inheritance in oops
PPTX
Inheritance in c++
PPT
Inheritance in C++
PPT
6 Inheritance
PPTX
Introduction to Inheritance
PPTX
INHERITANCE.pptx
PPTX
Inheritance
PPTX
inheritance
PPTX
Week 8 - OOP Inheritance11111111111.pptx
PPTX
Inheritance.pptx
PPTX
INHERITANCES.pptx
PPTX
Object Oriented Design and Programming Unit-03
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
Inheritance in c++
inheritance-16031525566nbhij56604452.pdf
Inheritance and Polymorphism in Oops
Inheritance in C++ (Programming Fundamentals)
Β 
lecture 6.pdf
Inheritance in c++ by Manan Pasricha
Inheritance
Inheritance in oops
Inheritance in c++
Inheritance in C++
6 Inheritance
Introduction to Inheritance
INHERITANCE.pptx
Inheritance
inheritance
Week 8 - OOP Inheritance11111111111.pptx
Inheritance.pptx
INHERITANCES.pptx
Object Oriented Design and Programming Unit-03

Recently uploaded (20)

PPTX
innovation process that make everything different.pptx
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Testing WebRTC applications at scale.pdf
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
E -tech empowerment technologies PowerPoint
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
Internet___Basics___Styled_ presentation
innovation process that make everything different.pptx
presentation_pfe-universite-molay-seltan.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
WebRTC in SignalWire - troubleshooting media negotiation
522797556-Unit-2-Temperature-measurement-1-1.pptx
An introduction to the IFRS (ISSB) Stndards.pdf
Testing WebRTC applications at scale.pdf
Introuction about WHO-FIC in ICD-10.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
INTERNET------BASICS-------UPDATED PPT PRESENTATION
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
The Internet -By the Numbers, Sri Lanka Edition
Β 
Job_Card_System_Styled_lorem_ipsum_.pptx
E -tech empowerment technologies PowerPoint
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Paper PDF World Game (s) Great Redesign.pdf
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Internet___Basics___Styled_ presentation

oop database doc for studevsgdy fdsyn hdf

  • 2. INHERITANCE οƒ˜ Inheritance: οƒΌ The capability of a class to derive properties and characteristics from another class is called Inheritance οƒΌ .Inheritance is one of the most important features of Object-Oriented Programming. οƒΌ Inheritance is a feature or a process in which, new classes are created from the existing classes. οƒΌ The new class created is called β€œderived class” or β€œchild class” and the existing class is known as the β€œbase class” or β€œparent class”. T οƒ˜ Syntax: class <derived_class_name> : <access-specifier> <base_class_name> { //body } οƒ˜ EXAMPLE: #include<iostream> using namespace std; class Person { int id; char name[100]; public: void set_p(); void display_p(); }; void Person::set_p() {
  • 3. cout<<"Enter the Id:"; cin>>id; cout<<"Enter the Name:"; cin>>name; } void Person::display_p() { cout<<endl<<"id: "<< id<<"nName: "<<name; } class Student: private Person { char course[50]; int fee; public: void set_s(); void display_s(); }; void Student::set_s() { set_p(); cout<<"Enter the Course Name:"; cin>>course; cout<<"Enter the Course Fee:"; cin>>fee; }
  • 4. void Student::display_s() { display_p(); cout<<"nCourse: "<<course<<"nFee: "<<fee<<endl; } int main() { Student s; s.set_s(); s.display_s(); return 0; } οƒ˜ Modes of Inheritance: There are 3 modes of inheritance. 1. Public Mode: If we derive a subclass from a public base class. Then the public member of the base class will become public in the derived class and protected members of the base class will become protected in the derived class. 2. Protected Mode: If we derive a subclass from a Protected base class. Then both public members and protected members of the base class will become protected in the derived class. 3. Private Mode: If we derive a subclass from a Private base class. Then both public members and protected members of the base class will become Private in the derived class. Types Of Inheritance:- 1. Single inheritance 2. Multilevel inheritance 3. Multiple inheritance 4. Hierarchical inheritance 5. Hybrid inheritance οƒ˜ Single Inheritance: In single inheritance, a class is allowed to inherit from only one class. i.e. one subclass is inherited by one base class only.
  • 5. οƒ˜ Syntax: class subclass_name : access_mode base_class { // body of subclass }; OR class A { ... .. ... }; class B: public A { ... .. ... }; ο‚· Multiple Inheritance: Multiple Inheritance is a feature of C++ where a class can inherit from more than one class. i.e one subclass is inherited from more than one base class. οƒ˜ Syntax: class subclass_name : access_mode base_class1, access_mode base_class2, .... { // body of subclass }; class B {
  • 6. ... .. }; class C { ... .. ... }; class A: public B, public C { ... ... ... }; οƒ˜ Multilevel Inheritance: In this type of inheritance, a derived class is created from another derived class. οƒ˜ Syntax: class C { ... .. ... }; class B:public C { ... .. ... }; class A: public B { ... ... ... }; οƒ˜ Hierarchical Inheritance: In this type of inheritance, more than one subclass is inherited from a single base class. i.e. more than one derived class is created from a single base class.
  • 7. ο‚· Syntax:- class A { // body of the class A. } class B : public A { // body of class B. } class C : public A { // body of class C. } class D : public A { // body of class D. } . Hybrid (Virtual) Inheritance: Hybrid Inheritance is implemented by combining more than one type of inheritance. For example: Combining Hierarchical inheritance and Multiple Inheritance. οƒ˜ Why we use inheritance?
  • 8. We use inheritance in C++ when both the classes in the program have the same logical domain and when we want the class to use the properties of its superclass along with its properties.