SlideShare a Scribd company logo
Contents
 Access Specifiers
 Derived Classes
 Type of Inheritance
 Derived class Constructors (Constructors in single
Inheritance)
 Multiple Inheritance
 Constructors in multiple Inheritance
 Constructors in single/multiple Inheritance with
arguments.
Inheritance
 Inheritance is the second most important feature of OOP.
 In inheritance, the code of existing classes is used for making new classes.
 This saves time for writing and debugging the entire code for a new class.
 To inherit means to receive.
 In inheritance a new class is written such that it can access or use the members of
an existing class.
 The new class that can access the members of an existing class is called the derived
class or child class. The existing class is called the base class or parent class.
Inheritance
 The derived class can use the data members and member functions of the
base class.
 It can also have its own data members and member functions.
 Thus a derived class can even be larger than a base class.
Inheritance
 The figure shows the relationship
between a derived class and the base
class.
 The arrow is drawn from the derived
class to the base class.
 The direction of the arrow indicates
that the derived class can access
members of the base class but base
class cannot access members of its
derived class.
 In the figure shown on the left, the
derived class has only one member of
its own. The two members shown in
dotted lines are the members of the
base class. The derived class can also
access these two members of the base
class. Thus, whereas an object of the
base class can access only two
members, an object of the derived
class can access three members. A
new class can be derived from one or
more existing Classes.
Specifiers
 Public [Already Discussed]
 Private [Already Discussed]
 Protected
 The public members of a class are accessible by all functions in the program and
the private members of a class are accessible only by member functions and friend
functions of that class. Similarly, the protected members of a class are accessible
by the member functions and friend functions of that Class.
 The protected members of a base class are, however, accessible by members of its
derived classes but the private members of the base class are not accessible
directly by members of its derived classes. This is the main difference between the
protected and the private access specifiers.
 The protected members of a base class fall between private and public member.
These members are public for the derived class but for the rest of the program,
these are treated as private.
Defining Derived Class
The syntax for defining a derived class is slightly different from the syntax of the
base class definition. The declaration of a derived class also includes the name
of the base class from which it is derived. The general syntax for defining a
derived class is:
class sub_class_name : specifier
base_class_name{ ………………………………….
members of derived class
………………………………………}
Where
sub_class_name : represents name of the derived class.
: (colon) sets relation between the classes.
specifier represents the access specifier. It may be public, private or
Protected, base_class_name : represents name of the base class.
For example, a class "student" is
defined as:
class student {
private: Char name[15], address[15];
public:
void input (void);
void show(void);
};
Example Explanation
 The class student has two data members and two member
functions. Suppose the marks obtained by a student in three
different subjects and the total marks of these subjects are to
be included as new data members in the above class. This is
done by adding new members in the class. There are two ways
in which these new members can be added to the class:
• Add new members in the original
• Define a new class that has the new members and that also
uses members of the existing "student" class. Using the
members of an existing class is the principle of inheritance.
The new class is the derived class. The existing class serves as
the base class for the derived class.
Defining Derived Class (cont…)
Driving a new class from the existing class reduces the size of the
program. It also eliminates duplication of code within the
program. For example, let the name of the new class be marks.
This class uses the members of the existing student class.
class marks : public student {
private:
int s1,s2,s3, total;
public:
void inputmarks(void);
void show_detail(void); };
Defining Derived Class (cont..)
 The cIass marks is derived from the class student. The class marks is the
derived class. The class student is the base class.
 The derived class has four data members of integer type and two member
functions.
 It also uses the code of the base class student.
 The derived class cannot directly access the private data members the base
class student by using the dot operator.
 These members are only accessible to the derived class through the
interface functions within the base class.
Types of Inheritance
 There are three kinds of inheritance.
• Public • Private • Protected
 Public Inheritance
In Public Inheritance, the public members of the base class
become the public members of the derived class.
Thus the objects of the derived class can access public
members (both data and functions) of the base class.
Similarly, the protected data members of the base class also
become the protected members of derived class.
The general syntax for deriving a public class
from base class is:
class sub_class_name : public base_class_name {
…………………
…………………
) ;
where
public: specifies the public inheritance.
sub_class__name: represents name of the derived class.
base_class_name: represents name of the base class.
Example: Public Inheritance
#include<iostream>
using namespace std;
class A {
private:
int a1,a2;
protected:
int pa1,pa2;
public:
void ppp (void){
cout<<"Value of pal of class
A="<<pa1<<endl;
cout<<"Value of pa2 of class
A="<<pa2<<endl; }};
class B : public A {
public:
void get(void){
cout << "Enter value pal ? ";
cin>>pa1;
cout<<"Enter value pa2 ?";
cin>>pa2;}};
main (){
B ob;
ob.get();
ob.ppp();
};
Example Explanation
In the above program the class B is publicly derived from class
A. The object of the class B
 Cannot access the private data member’s a1 & a2 of base class
A.
 Can access the public function member ppp of base class A.
 Can access the protected data members pa1 & pa2 of base
class A.
Private Inheritance
In private Inheritance the objects of the derived class cannot
access the public members of the base class. Its objects can only
access the protected data members of the base class.
The general syntax for deriving private class from base class is:
class sub_class_name : private base_class_name {
………………………………….}
Private: specifies private inheritance.
sub_class_name: represents name of the derived class.
base_class_name: represents name of the base class.
Example: Private Inheritance
#include<iostream>
using namespace std;
class A {
private:
int a1,a2;
protected:
int pa1,pa2;
public:
void ppp (void){
cout<<"Value of pa1 of class
A="<<pa1<<endl;
cout<<"Value of pa2 of class
A="<<pa2<<endl;}
};
class B : private A
{ public:
void get(void)
{cout<<"Enter value of pa1 ";
cin>>pa1;
cout<<"Enter value of pa2 =";
cin>>pa2;
cout<<"Value of pa1 of class
A="<<pa1<<endl;
cout<<"Value of pa2 of class
A="<<pa2<<endl;}};
main ( ){
B ob;
ob.get(); }
Example Explanation
In the above program, the class B is derived as private for the
base class A. The objects of class B:
 cannot access the private data members a1 & a2 of base class
A.
 cannot access the public function member ppp of base class A.
 can only access the protected data members pal & pa2 of base
class A.
Protected Inheritance
The object of the class that is derived as protected can access
only the protected member of the base class. The general syntax
for deriving a protected Class from base class is:
class sub_class_name: protected base_class_name {
…………………
…………………
};
where protected: specifies protected inheritance.
sub_class_name: represents name of the derived class.
Base_class_name: represents name of the base class.
Example: Protected Inheritance
#include<iostream>
using namespace std;
class A
{
private :
int a1,a2;
protected:
int pa1,pa2;
public:
void get(void){
cout<<"value of pa1 of class A ";
cout<<"value of pa2 of class A ?";}};
class B: protected A{
public:
void get (void){
cout<<" Enter value of pa1=";
cin>>pa1;
cout<<"Value of pa2";
cin>>pa2;
cout<<"Value of pa1 of class
A="<<pa1<<endl;
cout<<"Value of pa2 of class
A="<<pa2<<endl;}};
main(){
B ob;
ob.get(); }
Example Explanation
In the above program, thc class B is derived as protected from the
base class A. The objects of class B:
 can only access the protected data members pal &.pa2 of base
class A.
Derived Class Constructors
 In inheritance, a constructor of the derived class as well the
constructor functions of the base class are automatically
executed when an object of the derived class is created.
 The following example explains the concept of constructor
functions in single inheritance.
Example: Derived Class Constructors
#include<iostream>
using namespace std;
class bb{
public:
bb(void){
cout<<"Constructor of
base class"<<endl;
}
};
class dd:public bb{
public:
dd(void){
cout<<"Constructor of
derived class"<<endl;
}
};
main(){
dd abc;
}
Example Explanation
 In the above program, when an object of the derived class dd
is created, the constructors of both the derived class as well as
the base class are executed.
 
Multiple Inheritance
 In Multiple inheritances, a class is derived by using more than
one classes.
 In multiple inheritance the derived class receives the members
of two or more base classes.
 Multiple inheritance is a powerful feature of Object Oriented
Programming.
 This technique reduces the program size and save
programmer's. time. The programmer uses the existing base
classes in the program coding to solve problems.
 The figure shown below illustrates the relation of derived class
with base classes.
 
Multiple Inheritance
 
Multiple Inheritance
In the figure, Class C is derived from two base classes A & B. The syntax of
multiple inheritance is similar to that of single inheritance class. The name of
base classes are written separated by comma(,).
Syntax:
Class sub_class : sp1 b_class_1, sp2 b_class_2……..
{
………………………..
};
Where :
sp1 represents the access specifier of the first base class.
sp2 represents the access specifier of the second base class.
Example: Multiple Inheritance
#include<iostream>
using namespace std;
class student {
private:
char name[20],address[20];
public:
void input (void){
cout<<"Enter name:";cin>>name;
cout<<"Enter address:";cin>>address;
}
void print(void){
cout<<"Name:"<<name<<endl;
cout<<"Address:"<<address<<endl;
}
};
class marks {
private:
int s1,s2,total;
public:
void inputmarks(void){
cout<<"Enter marks of
S1=";cin>>s1;
cout<<"Enter marks of
S2=";cin>>s2;
total=s1+s2;}
void showmarks(void){
cout<<"Marks in s1="<<s1<<endl;
Example: Multiple Inheritance (Cont..)
cout<<"Marks in
s2="<<s2<<endl;
cout<<"Total
Marks="<<total<<endl;
}
};
class show: public student,
public marks{
public:
void showrec(){
cout<<"Record is"<<endl;
print();
showmarks();
}
};
main(){
show m;
m.input();
m.inputmarks();
m.showrec();
}
Constructor in Multiple Inheritance
 When a class is derived from more than one base classes, the constructor of
the derived class as well as all of its base classes are executed when an
object of the derived class is created.
 If the constructor functions have no parameters then first the constructor
functions of the base class are executed and then the constructor functions
of the derived class is executed.
Example: Constructor in Multiple Inheritance
#include<iostream>
using namespace std;
class aa{
public:
aa(){
cout<<"Class aa"<<endl;
}
};
class bb{
public:
bb(){
cout<<"Class bb"<<endl;
};
class cc:public aa,public bb{
public:
cc(){
cout<<"Class cc"<<endl;
}
};
main(){
cc o;
}
Example Explanation
 In the above program, three classes are created.
 The cc class is publicly derived from two class aa and bb.
 All the classes have constructor functions are executed in the
following sequence.
1. Constructor of class aa is executed first.
2. Constructor of class bb is executed second.
3. Constructor of class cc is executed last.

More Related Content

What's hot

Python-DataAbstarction.pptx
Python-DataAbstarction.pptxPython-DataAbstarction.pptx
Python-DataAbstarction.pptx
Karudaiyar Ganapathy
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
foreverredpb
 
Modular programming
Modular programmingModular programming
Structure de Contrôle
Structure de Contrôle Structure de Contrôle
Structure de Contrôle
InforMatica34
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Sikder Tahsin Al-Amin
 
Inheritance
InheritanceInheritance
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
yugandhar vadlamudi
 
Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3
MOHIT TOMAR
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
Nilesh Dalvi
 
Ref cursor
Ref cursorRef cursor
Ref cursor
pranav kumar verma
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
C functions
C functionsC functions
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
Nitin Jawla
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
Lovely Professional University
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
vampugani
 

What's hot (20)

Python-DataAbstarction.pptx
Python-DataAbstarction.pptxPython-DataAbstarction.pptx
Python-DataAbstarction.pptx
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
Modular programming
Modular programmingModular programming
Modular programming
 
Structure de Contrôle
Structure de Contrôle Structure de Contrôle
Structure de Contrôle
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Ref cursor
Ref cursorRef cursor
Ref cursor
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
C functions
C functionsC functions
C functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 

Viewers also liked

Abp Presentation
Abp PresentationAbp Presentation
Abp Presentation
pintsin2001
 
Alok tiwari main profile presentation
Alok tiwari main profile presentationAlok tiwari main profile presentation
Alok tiwari main profile presentation
Alok Tiwari
 
Seminar IM Interactive Workbook Progress
Seminar IM Interactive Workbook ProgressSeminar IM Interactive Workbook Progress
Seminar IM Interactive Workbook Progress
J Au
 
5 tips for better search
5 tips for better search5 tips for better search
5 tips for better search
Intranätverk
 
Tipos de sujeito
Tipos de sujeitoTipos de sujeito
Tipos de sujeito
Karen Olivan
 
A sintaxe da gramatica normativa ii
A sintaxe da gramatica normativa iiA sintaxe da gramatica normativa ii
A sintaxe da gramatica normativa ii
Iury Alberth
 
Sejarah Perkembangan Keperawatan
Sejarah Perkembangan KeperawatanSejarah Perkembangan Keperawatan
Sejarah Perkembangan Keperawatan
pjj_kemenkes
 
Inês quite e desforrada - Gil Vicente
Inês quite e desforrada - Gil VicenteInês quite e desforrada - Gil Vicente
Inês quite e desforrada - Gil Vicente
Gijasilvelitz 2
 
Cantigas de amigo
Cantigas de amigoCantigas de amigo
Cantigas de amigo
eduardo22urbano
 
Koneski Grécia antiga
Koneski Grécia antigaKoneski Grécia antiga
Koneski Grécia antiga
Tavinho Koneski Westphal
 
Koneski Formação do feudalismo Corrigido
Koneski Formação do feudalismo CorrigidoKoneski Formação do feudalismo Corrigido
Koneski Formação do feudalismo Corrigido
Tavinho Koneski Westphal
 
20170221 Estudio AudioOnline(V_Corta)
20170221 Estudio AudioOnline(V_Corta)20170221 Estudio AudioOnline(V_Corta)
20170221 Estudio AudioOnline(V_Corta)
OptimediaSpain
 
O que é e o que não ebd
O que é e o que não ebdO que é e o que não ebd
O que é e o que não ebd
Pastor Juscelino Freitas
 
A vida do apóstolo dos gentios
A vida do apóstolo dos gentiosA vida do apóstolo dos gentios
A vida do apóstolo dos gentios
MARCOS ANTONIO SANTOS DIAS
 
Llegir per gust. Escollim els premis de Sant Jordi
Llegir per gust. Escollim els premis de Sant JordiLlegir per gust. Escollim els premis de Sant Jordi
Llegir per gust. Escollim els premis de Sant Jordi
Escola La Farigola de Vallcarca
 

Viewers also liked (15)

Abp Presentation
Abp PresentationAbp Presentation
Abp Presentation
 
Alok tiwari main profile presentation
Alok tiwari main profile presentationAlok tiwari main profile presentation
Alok tiwari main profile presentation
 
Seminar IM Interactive Workbook Progress
Seminar IM Interactive Workbook ProgressSeminar IM Interactive Workbook Progress
Seminar IM Interactive Workbook Progress
 
5 tips for better search
5 tips for better search5 tips for better search
5 tips for better search
 
Tipos de sujeito
Tipos de sujeitoTipos de sujeito
Tipos de sujeito
 
A sintaxe da gramatica normativa ii
A sintaxe da gramatica normativa iiA sintaxe da gramatica normativa ii
A sintaxe da gramatica normativa ii
 
Sejarah Perkembangan Keperawatan
Sejarah Perkembangan KeperawatanSejarah Perkembangan Keperawatan
Sejarah Perkembangan Keperawatan
 
Inês quite e desforrada - Gil Vicente
Inês quite e desforrada - Gil VicenteInês quite e desforrada - Gil Vicente
Inês quite e desforrada - Gil Vicente
 
Cantigas de amigo
Cantigas de amigoCantigas de amigo
Cantigas de amigo
 
Koneski Grécia antiga
Koneski Grécia antigaKoneski Grécia antiga
Koneski Grécia antiga
 
Koneski Formação do feudalismo Corrigido
Koneski Formação do feudalismo CorrigidoKoneski Formação do feudalismo Corrigido
Koneski Formação do feudalismo Corrigido
 
20170221 Estudio AudioOnline(V_Corta)
20170221 Estudio AudioOnline(V_Corta)20170221 Estudio AudioOnline(V_Corta)
20170221 Estudio AudioOnline(V_Corta)
 
O que é e o que não ebd
O que é e o que não ebdO que é e o que não ebd
O que é e o que não ebd
 
A vida do apóstolo dos gentios
A vida do apóstolo dos gentiosA vida do apóstolo dos gentios
A vida do apóstolo dos gentios
 
Llegir per gust. Escollim els premis de Sant Jordi
Llegir per gust. Escollim els premis de Sant JordiLlegir per gust. Escollim els premis de Sant Jordi
Llegir per gust. Escollim els premis de Sant Jordi
 

Similar to inheritance

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
RAJ KUMAR
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
LadallaRajKumar
 
Inheritance
InheritanceInheritance
Inheritance
Burhan Ahmed
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
Inheritance
InheritanceInheritance
Inheritance
Pranali Chaudhari
 
Inheritance
Inheritance Inheritance
Inheritance
sourav verma
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
OOPs Lecture 2
OOPs Lecture 2OOPs Lecture 2
OOPs Lecture 2
Abbas Ajmal
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
SURBHI SAROHA
 
C++ Notes
C++ NotesC++ Notes
Inheritance
InheritanceInheritance
Inheritance
Munsif Ullah
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modes
Vinay Kumar
 
Inheritance
InheritanceInheritance
Inheritance
lykado0dles
 
Inheritance
InheritanceInheritance
Inheritance
Loy Calazan
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
Class properties
Class propertiesClass properties
Class properties
Siva Priya
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
Inheritance
InheritanceInheritance
Inheritance
zindadili
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 

Similar to inheritance (20)

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
Inheritance Inheritance
Inheritance
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
OOPs Lecture 2
OOPs Lecture 2OOPs Lecture 2
OOPs Lecture 2
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
Inheritance
InheritanceInheritance
Inheritance
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modes
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
 
Class properties
Class propertiesClass properties
Class properties
 
Class and object
Class and objectClass and object
Class and object
 
Inheritance
InheritanceInheritance
Inheritance
 
Class and object
Class and objectClass and object
Class and object
 

Recently uploaded

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 

Recently uploaded (20)

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 

inheritance

  • 1. Contents  Access Specifiers  Derived Classes  Type of Inheritance  Derived class Constructors (Constructors in single Inheritance)  Multiple Inheritance  Constructors in multiple Inheritance  Constructors in single/multiple Inheritance with arguments.
  • 2. Inheritance  Inheritance is the second most important feature of OOP.  In inheritance, the code of existing classes is used for making new classes.  This saves time for writing and debugging the entire code for a new class.  To inherit means to receive.  In inheritance a new class is written such that it can access or use the members of an existing class.  The new class that can access the members of an existing class is called the derived class or child class. The existing class is called the base class or parent class.
  • 3. Inheritance  The derived class can use the data members and member functions of the base class.  It can also have its own data members and member functions.  Thus a derived class can even be larger than a base class.
  • 4. Inheritance  The figure shows the relationship between a derived class and the base class.  The arrow is drawn from the derived class to the base class.  The direction of the arrow indicates that the derived class can access members of the base class but base class cannot access members of its derived class.  In the figure shown on the left, the derived class has only one member of its own. The two members shown in dotted lines are the members of the base class. The derived class can also access these two members of the base class. Thus, whereas an object of the base class can access only two members, an object of the derived class can access three members. A new class can be derived from one or more existing Classes.
  • 5. Specifiers  Public [Already Discussed]  Private [Already Discussed]  Protected  The public members of a class are accessible by all functions in the program and the private members of a class are accessible only by member functions and friend functions of that class. Similarly, the protected members of a class are accessible by the member functions and friend functions of that Class.  The protected members of a base class are, however, accessible by members of its derived classes but the private members of the base class are not accessible directly by members of its derived classes. This is the main difference between the protected and the private access specifiers.  The protected members of a base class fall between private and public member. These members are public for the derived class but for the rest of the program, these are treated as private.
  • 6. Defining Derived Class The syntax for defining a derived class is slightly different from the syntax of the base class definition. The declaration of a derived class also includes the name of the base class from which it is derived. The general syntax for defining a derived class is: class sub_class_name : specifier base_class_name{ …………………………………. members of derived class ………………………………………} Where sub_class_name : represents name of the derived class. : (colon) sets relation between the classes. specifier represents the access specifier. It may be public, private or Protected, base_class_name : represents name of the base class.
  • 7. For example, a class "student" is defined as: class student { private: Char name[15], address[15]; public: void input (void); void show(void); };
  • 8. Example Explanation  The class student has two data members and two member functions. Suppose the marks obtained by a student in three different subjects and the total marks of these subjects are to be included as new data members in the above class. This is done by adding new members in the class. There are two ways in which these new members can be added to the class: • Add new members in the original • Define a new class that has the new members and that also uses members of the existing "student" class. Using the members of an existing class is the principle of inheritance. The new class is the derived class. The existing class serves as the base class for the derived class.
  • 9. Defining Derived Class (cont…) Driving a new class from the existing class reduces the size of the program. It also eliminates duplication of code within the program. For example, let the name of the new class be marks. This class uses the members of the existing student class. class marks : public student { private: int s1,s2,s3, total; public: void inputmarks(void); void show_detail(void); };
  • 10. Defining Derived Class (cont..)  The cIass marks is derived from the class student. The class marks is the derived class. The class student is the base class.  The derived class has four data members of integer type and two member functions.  It also uses the code of the base class student.  The derived class cannot directly access the private data members the base class student by using the dot operator.  These members are only accessible to the derived class through the interface functions within the base class.
  • 11. Types of Inheritance  There are three kinds of inheritance. • Public • Private • Protected  Public Inheritance In Public Inheritance, the public members of the base class become the public members of the derived class. Thus the objects of the derived class can access public members (both data and functions) of the base class. Similarly, the protected data members of the base class also become the protected members of derived class.
  • 12. The general syntax for deriving a public class from base class is: class sub_class_name : public base_class_name { ………………… ………………… ) ; where public: specifies the public inheritance. sub_class__name: represents name of the derived class. base_class_name: represents name of the base class.
  • 13. Example: Public Inheritance #include<iostream> using namespace std; class A { private: int a1,a2; protected: int pa1,pa2; public: void ppp (void){ cout<<"Value of pal of class A="<<pa1<<endl; cout<<"Value of pa2 of class A="<<pa2<<endl; }}; class B : public A { public: void get(void){ cout << "Enter value pal ? "; cin>>pa1; cout<<"Enter value pa2 ?"; cin>>pa2;}}; main (){ B ob; ob.get(); ob.ppp(); };
  • 14. Example Explanation In the above program the class B is publicly derived from class A. The object of the class B  Cannot access the private data member’s a1 & a2 of base class A.  Can access the public function member ppp of base class A.  Can access the protected data members pa1 & pa2 of base class A.
  • 15. Private Inheritance In private Inheritance the objects of the derived class cannot access the public members of the base class. Its objects can only access the protected data members of the base class. The general syntax for deriving private class from base class is: class sub_class_name : private base_class_name { ………………………………….} Private: specifies private inheritance. sub_class_name: represents name of the derived class. base_class_name: represents name of the base class.
  • 16. Example: Private Inheritance #include<iostream> using namespace std; class A { private: int a1,a2; protected: int pa1,pa2; public: void ppp (void){ cout<<"Value of pa1 of class A="<<pa1<<endl; cout<<"Value of pa2 of class A="<<pa2<<endl;} }; class B : private A { public: void get(void) {cout<<"Enter value of pa1 "; cin>>pa1; cout<<"Enter value of pa2 ="; cin>>pa2; cout<<"Value of pa1 of class A="<<pa1<<endl; cout<<"Value of pa2 of class A="<<pa2<<endl;}}; main ( ){ B ob; ob.get(); }
  • 17. Example Explanation In the above program, the class B is derived as private for the base class A. The objects of class B:  cannot access the private data members a1 & a2 of base class A.  cannot access the public function member ppp of base class A.  can only access the protected data members pal & pa2 of base class A.
  • 18. Protected Inheritance The object of the class that is derived as protected can access only the protected member of the base class. The general syntax for deriving a protected Class from base class is: class sub_class_name: protected base_class_name { ………………… ………………… }; where protected: specifies protected inheritance. sub_class_name: represents name of the derived class. Base_class_name: represents name of the base class.
  • 19. Example: Protected Inheritance #include<iostream> using namespace std; class A { private : int a1,a2; protected: int pa1,pa2; public: void get(void){ cout<<"value of pa1 of class A "; cout<<"value of pa2 of class A ?";}}; class B: protected A{ public: void get (void){ cout<<" Enter value of pa1="; cin>>pa1; cout<<"Value of pa2"; cin>>pa2; cout<<"Value of pa1 of class A="<<pa1<<endl; cout<<"Value of pa2 of class A="<<pa2<<endl;}}; main(){ B ob; ob.get(); }
  • 20. Example Explanation In the above program, thc class B is derived as protected from the base class A. The objects of class B:  can only access the protected data members pal &.pa2 of base class A.
  • 21. Derived Class Constructors  In inheritance, a constructor of the derived class as well the constructor functions of the base class are automatically executed when an object of the derived class is created.  The following example explains the concept of constructor functions in single inheritance.
  • 22. Example: Derived Class Constructors #include<iostream> using namespace std; class bb{ public: bb(void){ cout<<"Constructor of base class"<<endl; } }; class dd:public bb{ public: dd(void){ cout<<"Constructor of derived class"<<endl; } }; main(){ dd abc; }
  • 23. Example Explanation  In the above program, when an object of the derived class dd is created, the constructors of both the derived class as well as the base class are executed.
  • 24.   Multiple Inheritance  In Multiple inheritances, a class is derived by using more than one classes.  In multiple inheritance the derived class receives the members of two or more base classes.  Multiple inheritance is a powerful feature of Object Oriented Programming.  This technique reduces the program size and save programmer's. time. The programmer uses the existing base classes in the program coding to solve problems.  The figure shown below illustrates the relation of derived class with base classes.
  • 26.   Multiple Inheritance In the figure, Class C is derived from two base classes A & B. The syntax of multiple inheritance is similar to that of single inheritance class. The name of base classes are written separated by comma(,). Syntax: Class sub_class : sp1 b_class_1, sp2 b_class_2…….. { ……………………….. }; Where : sp1 represents the access specifier of the first base class. sp2 represents the access specifier of the second base class.
  • 27. Example: Multiple Inheritance #include<iostream> using namespace std; class student { private: char name[20],address[20]; public: void input (void){ cout<<"Enter name:";cin>>name; cout<<"Enter address:";cin>>address; } void print(void){ cout<<"Name:"<<name<<endl; cout<<"Address:"<<address<<endl; } }; class marks { private: int s1,s2,total; public: void inputmarks(void){ cout<<"Enter marks of S1=";cin>>s1; cout<<"Enter marks of S2=";cin>>s2; total=s1+s2;} void showmarks(void){ cout<<"Marks in s1="<<s1<<endl;
  • 28. Example: Multiple Inheritance (Cont..) cout<<"Marks in s2="<<s2<<endl; cout<<"Total Marks="<<total<<endl; } }; class show: public student, public marks{ public: void showrec(){ cout<<"Record is"<<endl; print(); showmarks(); } }; main(){ show m; m.input(); m.inputmarks(); m.showrec(); }
  • 29. Constructor in Multiple Inheritance  When a class is derived from more than one base classes, the constructor of the derived class as well as all of its base classes are executed when an object of the derived class is created.  If the constructor functions have no parameters then first the constructor functions of the base class are executed and then the constructor functions of the derived class is executed.
  • 30. Example: Constructor in Multiple Inheritance #include<iostream> using namespace std; class aa{ public: aa(){ cout<<"Class aa"<<endl; } }; class bb{ public: bb(){ cout<<"Class bb"<<endl; }; class cc:public aa,public bb{ public: cc(){ cout<<"Class cc"<<endl; } }; main(){ cc o; }
  • 31. Example Explanation  In the above program, three classes are created.  The cc class is publicly derived from two class aa and bb.  All the classes have constructor functions are executed in the following sequence. 1. Constructor of class aa is executed first. 2. Constructor of class bb is executed second. 3. Constructor of class cc is executed last.