SlideShare a Scribd company logo
by
G.GowriLatha,M.Sc (Info Tech),
Department of CS&IT
Nadar Saraswathi college of arts and
science, Theni
BA
A
B
C
(i) SINGLE INHERITANCE
(ii)MULTIPLE INHERRITANCE
A
B C
A
B
C
D
(iii) HIERACHICAL
INHERITANCE
(iv) MULTILEVEL
 Base class to derived as
the derived class.
A
B C
D
(v) Hybrid inheritance
Class derived-class name : visibility base
class-name
{
----------------------------------
Member function
----------------------------------
}
 The public data member and three public member
function.
 B base class and D derived class.
 The class D contains one private data member and two
public member function.
EXAMPLE PROGRAM:
#include<iostream.h >
#include<conio.h>
class student
{
public:
int rno;
char name[20];
void getdata()
}
Cout<<“Enter RollNo : -t”;
Cin>>rno;
Cout<<“enter name :-t”
Cin>>name;
}
};
class marks : public student
{
Public:
int m1,m2,m3,tot;
float per;
Void getmarks()
{
Getdata();
Cout<<“enter mark1:-t”;
Cin>>m1;
Cout<<“enter mark2:-t”;
Cin>>m2;
Cout<<“enter mark3:-t”;
Cin>>m3;
}
Void display()
{
Getmarks();
Cout<<“RollNo t namet
mark1 t mark2 t mark3 t
total t percentage”;
Cout<<rno<<“t”;<<name<<“
t”<<m1<<“t”<<m2<<“t”<<
m3<<“t”<<tot<<“t”<<per;
}
};
Void main()
{
Student std;
Clrscr();
Std.getmarks();
Std.display();
Getch();
}
 The mechanism of the
derived class D.
 Private derivation the
public members of the
base class become private
members of the derived
class.
 The private data need from inherited by a derived
class, the private member making it public.
 A member declared as protected is accessible by the
member function with
private : //optional.
--------------//visible to member function.
--------------//with in its class.
Protected:
---------------//write member function.
---------------//of its own and derived class.
Public:
---------------//write to all functions.
---------------//with in the program.
private
protected
public
private
private
private
protected
protected
protected
public
public
public
Class BNot inheritable
Class D1: public B
Class D2: private B
Class X: public D1protected D2
The access control to the
private and protected
member of a class. They
could be,
 A functions that is a friend
of a class.
 A member function of a
class that is a friend of a
class.
 A member function of a
derived class.
 The class A serve as a
base class for the
derived class B.
 The class B is known
as intermediate base
class provide a link for
the inheritance
between A and C.
All users
Derived class
Member
function
Own member function
Friend function
class
public
protected
private
A
B
C
Base class Grand father
Intermediate base class father
Derived class child
#include<iostream.h>
#include<conio.h>
Class student {
Protected:
int rno,m1,m2;
Public:
void get() {
cout<<“enter the roll no:”;
Cin>>rno;
Cout<<“enter the mark1:”:
Cin>>m1;
Cout<<“enter the mark2:”;
Cin>>m2;
} };
Class sports {
Protected:
Int sm;
Public:
Void getsm() {
Cout<<“enter the sports mark:”;
Cin>>sm;
} };
Class statement: public student,
public sports {
Int tot,avg;
Public:
Void display() {
Tot =(m1+m2+sm);
Avg=tot/3;
Cout<<“nnt roll
no:”<<rno<<“nt
total:”<<tot;
Cout<<“nt
average:”<<avg;
} };
Void main() {
clrscr();
Statement obj;
Obj.get();
Obj.getsm();
Obj.display();
Getch();
}
Output:
Enter the roll no:100
Enter two marks
90
80
Enter the sports mark:90
Roll no:100
Total :260
Average :86.66
 A class can inherit the
attributes of two or more
classes.
 This known as multiple
inheritance.
Syntax:
EXAMPLE PROGRAM:
#include<iostream.h>
using namespace std;
class A
{
public:
B-1 B-2 B-n
D
Class D: visibility B-1,visibility B-2 …..
{
--------------------------
-----(Body of D)-----
---------------------------
}
A() {
Cout<<“A ‘s constructor
called”<<end1; } };
Class B {
Public:
B() {
Cout<<“B ‘s constructor
called”<<end1; } };
Class C:public B,public A
{ public:
C() {
Cout<<“C ‘s constructor
called”<<end1; } };
Int main()
{
C c;
return 0;
}
Output:
B’s constructor called
A’s constructor called
C’s constructor called
 One class may be
inherited by more than
one class.
 This process is known as
hierarchical inheritance.
 When more than one
classes are derived from
a single base class , such
inheritance is known as
hierarchical inheritance,
where feature that are
common in lower level are
included in parent class.
student
arts
medical
engineering
mech elec civil
 Hybrid inheritance is also
called as virtual base
class.
 A class is derived from
classes as in multiple
inheritance.
 One of the parent
classes is not a base
class .It is a derived
class.
 Multiple or multilevel type
of inheritance are used
to derive a class
.
EXAMPLE PROGRAM:
#include<bits/stdc++.h>
using namespace std;
class parent
{ public:
Int id_p; };
Class child : public parent
{
public :
int id_c;
};
Int main()
{
child obj1;
obj1.id_c=7;
obj1.id_p=91;
Cout<<“child id
is”<<obj1.id_c<<end1;
Cout<<“parent id
is”<<obj1.id_p<<end1;
return 0;
}
OUTPUT:
child id is 7
parent id is 91
studen
t
test
result
sports
Inheritance

More Related Content

What's hot

Roadmap to Object Oriented Programming
Roadmap to Object Oriented ProgrammingRoadmap to Object Oriented Programming
Roadmap to Object Oriented Programming
ssuser6fc8b1
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paper
Deepak Singh
 
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Salar Delavar Qashqai
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritance
zindadili
 
C Structure and Union in C
C Structure and Union in CC Structure and Union in C
Programs of C++
Programs of C++Programs of C++
L10
L10L10
L10
lksoo
 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question Paper
Malathi Senthil
 
Oop l2
Oop l2Oop l2
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
Kho コー。イエー。イエン
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
Deepak Singh
 
Sample Paper Class XI (Informatics Practices)
Sample Paper Class XI (Informatics Practices)Sample Paper Class XI (Informatics Practices)
Sample Paper Class XI (Informatics Practices)
Poonam Chopra
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
Jay Patel
 
C questions
C questionsC questions
C questions
MD Rashid
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
FALLEE31188
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
Kho コー。イエー。イエン
 
C program report tips
C program report tipsC program report tips
C program report tips
Harry Pott
 
CS50 Lecture4
CS50 Lecture4CS50 Lecture4
CS50 Lecture4
昀 李
 

What's hot (20)

Roadmap to Object Oriented Programming
Roadmap to Object Oriented ProgrammingRoadmap to Object Oriented Programming
Roadmap to Object Oriented Programming
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paper
 
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritance
 
C Structure and Union in C
C Structure and Union in CC Structure and Union in C
C Structure and Union in C
 
Programs of C++
Programs of C++Programs of C++
Programs of C++
 
L10
L10L10
L10
 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question Paper
 
Oop l2
Oop l2Oop l2
Oop l2
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
 
Sample Paper Class XI (Informatics Practices)
Sample Paper Class XI (Informatics Practices)Sample Paper Class XI (Informatics Practices)
Sample Paper Class XI (Informatics Practices)
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
 
C questions
C questionsC questions
C questions
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
 
C program report tips
C program report tipsC program report tips
C program report tips
 
CS50 Lecture4
CS50 Lecture4CS50 Lecture4
CS50 Lecture4
 

Similar to Inheritance

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
RutujaTandalwade
 
Unit 4
Unit 4Unit 4
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
study material
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.ppt
BArulmozhi
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
abhilashagupta
 
Lecture4
Lecture4Lecture4
Lecture4
rajesh0ks
 
Lecture4
Lecture4Lecture4
Lecture4
FALLEE31188
 
What is inheritance
What is inheritanceWhat is inheritance
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
zindadili
 
Inheritance
InheritanceInheritance
Inheritance
Burhan Ahmed
 
inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPM
PKKArc
 
Bc0037
Bc0037Bc0037
Bc0037
hayerpa
 
2.6 Types of Inheritance in OOP C++.pptx
2.6 Types of Inheritance in OOP C++.pptx2.6 Types of Inheritance in OOP C++.pptx
2.6 Types of Inheritance in OOP C++.pptx
tirseishwaricomp
 
Lecture4
Lecture4Lecture4
Lecture4
Ravi Kant Kumar
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
Inheritance in C++.ppt
Inheritance in C++.pptInheritance in C++.ppt
Inheritance in C++.ppt
instaface
 
Lecture07
Lecture07Lecture07
Lecture07
elearning_portal
 

Similar to Inheritance (20)

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Unit 4
Unit 4Unit 4
Unit 4
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.ppt
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
What is inheritance
What is inheritanceWhat is inheritance
What is inheritance
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPM
 
Bc0037
Bc0037Bc0037
Bc0037
 
2.6 Types of Inheritance in OOP C++.pptx
2.6 Types of Inheritance in OOP C++.pptx2.6 Types of Inheritance in OOP C++.pptx
2.6 Types of Inheritance in OOP C++.pptx
 
Lecture4
Lecture4Lecture4
Lecture4
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Inheritance in C++.ppt
Inheritance in C++.pptInheritance in C++.ppt
Inheritance in C++.ppt
 
Lecture07
Lecture07Lecture07
Lecture07
 

More from GowriLatha1

Filtering in frequency domain
Filtering in frequency domainFiltering in frequency domain
Filtering in frequency domain
GowriLatha1
 
Demand assigned and packet reservation multiple access
Demand assigned and packet reservation multiple accessDemand assigned and packet reservation multiple access
Demand assigned and packet reservation multiple access
GowriLatha1
 
Software engineering
Software engineeringSoftware engineering
Software engineering
GowriLatha1
 
Shadow paging
Shadow pagingShadow paging
Shadow paging
GowriLatha1
 
Multithreading
MultithreadingMultithreading
Multithreading
GowriLatha1
 
Hive
HiveHive
Web services & com+ components
Web services & com+ componentsWeb services & com+ components
Web services & com+ components
GowriLatha1
 
Comparison with Traditional databases
Comparison with Traditional databasesComparison with Traditional databases
Comparison with Traditional databases
GowriLatha1
 
Recovery system
Recovery systemRecovery system
Recovery system
GowriLatha1
 
Comparison with Traditional databases
Comparison with Traditional databasesComparison with Traditional databases
Comparison with Traditional databases
GowriLatha1
 
Static analysis
Static analysisStatic analysis
Static analysis
GowriLatha1
 
Hema dm
Hema dmHema dm
Hema dm
GowriLatha1
 
Data reduction
Data reductionData reduction
Data reduction
GowriLatha1
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
GowriLatha1
 
computer network
computer networkcomputer network
computer network
GowriLatha1
 
Operating System
Operating SystemOperating System
Operating System
GowriLatha1
 
Data mining query language
Data mining query languageData mining query language
Data mining query language
GowriLatha1
 
Enterprice java
Enterprice javaEnterprice java
Enterprice java
GowriLatha1
 
Ethernet
EthernetEthernet
Ethernet
GowriLatha1
 
Java script
Java scriptJava script
Java script
GowriLatha1
 

More from GowriLatha1 (20)

Filtering in frequency domain
Filtering in frequency domainFiltering in frequency domain
Filtering in frequency domain
 
Demand assigned and packet reservation multiple access
Demand assigned and packet reservation multiple accessDemand assigned and packet reservation multiple access
Demand assigned and packet reservation multiple access
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Shadow paging
Shadow pagingShadow paging
Shadow paging
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Hive
HiveHive
Hive
 
Web services & com+ components
Web services & com+ componentsWeb services & com+ components
Web services & com+ components
 
Comparison with Traditional databases
Comparison with Traditional databasesComparison with Traditional databases
Comparison with Traditional databases
 
Recovery system
Recovery systemRecovery system
Recovery system
 
Comparison with Traditional databases
Comparison with Traditional databasesComparison with Traditional databases
Comparison with Traditional databases
 
Static analysis
Static analysisStatic analysis
Static analysis
 
Hema dm
Hema dmHema dm
Hema dm
 
Data reduction
Data reductionData reduction
Data reduction
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
computer network
computer networkcomputer network
computer network
 
Operating System
Operating SystemOperating System
Operating System
 
Data mining query language
Data mining query languageData mining query language
Data mining query language
 
Enterprice java
Enterprice javaEnterprice java
Enterprice java
 
Ethernet
EthernetEthernet
Ethernet
 
Java script
Java scriptJava script
Java script
 

Recently uploaded

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Inheritance

  • 1. by G.GowriLatha,M.Sc (Info Tech), Department of CS&IT Nadar Saraswathi college of arts and science, Theni
  • 2.
  • 3. BA A B C (i) SINGLE INHERITANCE (ii)MULTIPLE INHERRITANCE A B C A B C D (iii) HIERACHICAL INHERITANCE (iv) MULTILEVEL
  • 4.  Base class to derived as the derived class. A B C D (v) Hybrid inheritance Class derived-class name : visibility base class-name { ---------------------------------- Member function ---------------------------------- }
  • 5.  The public data member and three public member function.  B base class and D derived class.  The class D contains one private data member and two public member function. EXAMPLE PROGRAM: #include<iostream.h > #include<conio.h> class student { public: int rno;
  • 6. char name[20]; void getdata() } Cout<<“Enter RollNo : -t”; Cin>>rno; Cout<<“enter name :-t” Cin>>name; } }; class marks : public student { Public: int m1,m2,m3,tot; float per; Void getmarks() { Getdata(); Cout<<“enter mark1:-t”; Cin>>m1; Cout<<“enter mark2:-t”; Cin>>m2; Cout<<“enter mark3:-t”; Cin>>m3; } Void display() { Getmarks();
  • 7. Cout<<“RollNo t namet mark1 t mark2 t mark3 t total t percentage”; Cout<<rno<<“t”;<<name<<“ t”<<m1<<“t”<<m2<<“t”<< m3<<“t”<<tot<<“t”<<per; } }; Void main() { Student std; Clrscr(); Std.getmarks(); Std.display(); Getch(); }  The mechanism of the derived class D.  Private derivation the public members of the base class become private members of the derived class.
  • 8.  The private data need from inherited by a derived class, the private member making it public.  A member declared as protected is accessible by the member function with private : //optional. --------------//visible to member function. --------------//with in its class. Protected: ---------------//write member function. ---------------//of its own and derived class. Public: ---------------//write to all functions. ---------------//with in the program.
  • 10. The access control to the private and protected member of a class. They could be,  A functions that is a friend of a class.  A member function of a class that is a friend of a class.  A member function of a derived class.  The class A serve as a base class for the derived class B.  The class B is known as intermediate base class provide a link for the inheritance between A and C.
  • 11. All users Derived class Member function Own member function Friend function class public protected private A B C Base class Grand father Intermediate base class father Derived class child
  • 12. #include<iostream.h> #include<conio.h> Class student { Protected: int rno,m1,m2; Public: void get() { cout<<“enter the roll no:”; Cin>>rno; Cout<<“enter the mark1:”: Cin>>m1; Cout<<“enter the mark2:”; Cin>>m2; } }; Class sports { Protected: Int sm; Public: Void getsm() { Cout<<“enter the sports mark:”; Cin>>sm; } }; Class statement: public student, public sports { Int tot,avg; Public: Void display() { Tot =(m1+m2+sm); Avg=tot/3;
  • 13. Cout<<“nnt roll no:”<<rno<<“nt total:”<<tot; Cout<<“nt average:”<<avg; } }; Void main() { clrscr(); Statement obj; Obj.get(); Obj.getsm(); Obj.display(); Getch(); } Output: Enter the roll no:100 Enter two marks 90 80 Enter the sports mark:90 Roll no:100 Total :260 Average :86.66
  • 14.  A class can inherit the attributes of two or more classes.  This known as multiple inheritance. Syntax: EXAMPLE PROGRAM: #include<iostream.h> using namespace std; class A { public: B-1 B-2 B-n D Class D: visibility B-1,visibility B-2 ….. { -------------------------- -----(Body of D)----- --------------------------- }
  • 15. A() { Cout<<“A ‘s constructor called”<<end1; } }; Class B { Public: B() { Cout<<“B ‘s constructor called”<<end1; } }; Class C:public B,public A { public: C() { Cout<<“C ‘s constructor called”<<end1; } }; Int main() { C c; return 0; } Output: B’s constructor called A’s constructor called C’s constructor called
  • 16.  One class may be inherited by more than one class.  This process is known as hierarchical inheritance.  When more than one classes are derived from a single base class , such inheritance is known as hierarchical inheritance, where feature that are common in lower level are included in parent class. student arts medical engineering mech elec civil
  • 17.  Hybrid inheritance is also called as virtual base class.  A class is derived from classes as in multiple inheritance.  One of the parent classes is not a base class .It is a derived class.  Multiple or multilevel type of inheritance are used to derive a class . EXAMPLE PROGRAM: #include<bits/stdc++.h> using namespace std; class parent { public: Int id_p; }; Class child : public parent { public : int id_c; }; Int main()
  • 18. { child obj1; obj1.id_c=7; obj1.id_p=91; Cout<<“child id is”<<obj1.id_c<<end1; Cout<<“parent id is”<<obj1.id_p<<end1; return 0; } OUTPUT: child id is 7 parent id is 91 studen t test result sports