SlideShare a Scribd company logo
1 of 31
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
FASILKM
fasilemv@gmail.com
www.facebook.com/Fasilfaas
twitter.com/fasilemv
in.linkedin.com/in/fasilemv
9544334000
INHERITANCE
CONTENTS
• CLASS
• OBJECT
• INHERITANCE
SINGLE INHERITANCE
MULTIPLE INHERITANCE
HIERARCHICAL INHERITANCE
MULTILEVEL INHERITANCE
HYBRID INHERITANS(Virtual
Inheritance)
CLASS
• Class is the base design of objects
means expanded concept of a data,
that can hold both data and functions.
• No memory is allocated when class is
created.
• It is a user defined data type.
Example : A car is consider
as a class
Methods : Engine, wheels,
steering.
Properties : company,
model, colour,
speed, etc….
OBJECT
• Object is the instance of class, means
identifiable entity with some
characteristics and behaviour.
• Memory allocated when only an
object is created.
INHERITANCE
 Deriving new class from existing class.
 Object of one class contains the
property of another class.
 Reusability.
 We can add features to an
existing class without modifying it.
TYPES OF INHERITANCE
• Single Inheritance
• Hierarchical Inheritance
• Multi Level Inheritance
• Hybrid Inheritance
• Multiple Inheritance
SINGLE INHERITANCE
• One derived class inherits
from only one base class
• Most simplest form of
Inheritance.
SINGLE INHERITANCE
A
B
EXAMPLE
#include<iostream>
using namespace std;
class father
{
public:
string name;
int age,pincode;
};
class child:public father
{
public:
string school;
int standard;
};
main()
{
father obj1;
child obj2;
cout<<"enter the name of father:";
cin>>obj1.name;
cout<<"enter the age of father:";
cin>>obj1.age;
cout<<"enter the pincode of father:";
cin>>obj1.pincode;
cout<<"-------------DETAIL OF CHILD--------------n";
cout<<"enter the name of child:";
cin>>obj2.name;
cout<<"enter the age of child:";
cin>>obj2.age;
cout<<"enter the pincode of child:";
cin>>obj2.pincode;
cout<<"enter the school name of child:";
cin>>obj2.school;
cout<<"enter the standard of child:";
cin>>obj2.standard;
}
HEIRARCHICAL INHERITANCE
• More than one derived
classes is derived from
common base class.
HIERARCHICAL INHERITANCE
A
C DB
EXAMPLE
#include<iostream>
using namespace std;
class user
{
public:
string name,place;
int age;
};
class student:public user
{
public:
int rollno,classs,mark1,mark2;
};
class teacher:public user
{
public:
string department;
int teacher_id,salary;
};
main()
{
user obj;
student obj1;
teacher obj2;
cout<<"-----------------STUDENT-------------n";
cout<<"enter the name:";
cin>>obj1.name;
cout<<"enter the age:";
cin>>obj1.age;
cout<<"enter the place:";
cin>>obj1.place;
cout<<"enter the rollno:";
cin>>obj1.rollno;
cout<<"enter the class:";
cin>>obj1.classs;
cout<<"enter the mark1:";
cin>>obj1.mark1;
cout<<"enter the mark2:";
cin>>obj1.mark2;
cout<<"---------------TEACHER---------------n";
cout<<"enter the name:";
cin>>obj2.name;
cout<<"enter the age:";
cin>>obj2.age;
cout<<"enter the place:";
cin>>obj2.place;
cout<<"enter the id:";
cin>>obj2.teacher_id;
cout<<"enter the salary:";
cin>>obj2.salary;
cout<<"enter the department:";
cin>>obj2.department;
}
MULTI LEVEL INHERITANCE
• Derived class is derived
from another derived class.
MULTILEVEL INHERITANCE
A
B
C
EXAMPLE
#include<iostream>
using namespace std;
class grandparent
{
public:
void gshow()
{
cout<<"intelligent";
}
};
class parent:public grandparent
{
public:
void pshow()
{
cout<<"nhandsom";
}
};
class child:public parent
{
public:
void cshow()
{
cout<<"nobedience";
}
};
main()
{
grandparent obj1;
parent obj2;
child obj3;
cout<<"QUALITY OF GRANDPAn";
obj1.gshow();
cout<<"nQUALITIES OF FATHERn";
obj2.gshow();
obj2.pshow();
cout<<"nQUALITIES OF CHILDn";
obj3.gshow();
obj3.pshow();
obj3.cshow();
}
HYBRID INHERITANCE
• Combination of single
Inheritance , hierarchical
inheritance and
multi level inheritance.
HYBRID INHERITANCE
A
DB
C
EXAMPLE
#include<iostream>
using namespace std;
class grandparent
{
public:void gshow()
{
cout<<"nintelligent";
}
};
class parent:public grandparent
{
public:
void pshow()
{
cout<<"neducated";
}
};
class son:public parent
{
public:
void sshow()
{
cout<<"nobedience";
}
};
class daugter:public parent
{
public:
void dshow()
{
cout<<"nbeautiful";
}
};
main()
{
grandparent gobj;
parent pobj;
son sobj;
daugter dobj;
cout<<"QUALITY OF GRANDPA";
gobj.gshow();
cout<<"nQUALITY OF PARENT";
pobj.gshow();
pobj.pshow();
cout<<"nQUALITIES OF SON";
sobj.sshow();
sobj.pshow();
sobj.gshow();
cout<<"nQUALITIES OF DAUGHTER";
dobj.dshow();
dobj.pshow();
dobj.gshow();
}
MULTIPLE INHERITANCE
• Derived class is derived
from more than one
base class.
MULTIPLE INHERITANCE
A B
C
EXAMPLE
#include<iostream>
using namespace std;
class father
{
public:
void fshow()
{
cout<<"discipline";
}
};
class mother
{
public:
void mshow()
{
cout<<"nopen minded";
}
};
class child:public father,public mother
{
public:
void cshow()
{
cout<<"nintelligent";
}
};
main()
{
father obj1;
mother obj2;
child obj3;
cout<<"QUALITY OF FATHERn";
obj1.fshow();
cout<<"n";
cout<<"nQUALITY OF MOTHER";
obj2.mshow();
cout<<"n";
cout<<"nQUALITIES OF CHILDn";
obj3.fshow();
obj3.mshow();
obj3.cshow();
}
CONCLUSION
We can REUSE the methods and data of the
existing class
We can EXTEND the existing class by adding new
data and new methods
We can MODIFY the existing class by overloading
its methods with your own implementations
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us

More Related Content

Viewers also liked

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Laxman Puri
 

Viewers also liked (19)

Oop cocepts
Oop coceptsOop cocepts
Oop cocepts
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Project guidance for MSc Computer Science students
Project guidance for MSc Computer Science studentsProject guidance for MSc Computer Science students
Project guidance for MSc Computer Science students
 
Additional skill development program pk cics
Additional skill development program   pk cicsAdditional skill development program   pk cics
Additional skill development program pk cics
 
E paper
E paperE paper
E paper
 
Chapter 3 : Log on to Internet
Chapter  3 : Log on to InternetChapter  3 : Log on to Internet
Chapter 3 : Log on to Internet
 
Asp.net controls
Asp.net controlsAsp.net controls
Asp.net controls
 
Infrastructure requirements for an school in uae
Infrastructure requirements for an school in uae Infrastructure requirements for an school in uae
Infrastructure requirements for an school in uae
 
Stored procedures with cursors
Stored procedures with cursorsStored procedures with cursors
Stored procedures with cursors
 
Ajax
AjaxAjax
Ajax
 
My sql udf,views
My sql udf,viewsMy sql udf,views
My sql udf,views
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 

Similar to Inheritance

C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectsecondakay
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructorsanitashinde33
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on lineMilind Patil
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classsdjdskjd9097
 
OOP PPT 1.pptx
OOP PPT 1.pptxOOP PPT 1.pptx
OOP PPT 1.pptxlathass5
 
Intro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suIntro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suImranAliQureshi3
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Abdullah Jan
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classccis224477
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classcis247
 
class and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptxclass and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptxAshrithaRokkam
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)Jyoti shukla
 
Iterative Methodology for Personalization Models Optimization
 Iterative Methodology for Personalization Models Optimization Iterative Methodology for Personalization Models Optimization
Iterative Methodology for Personalization Models OptimizationSonya Liberman
 

Similar to Inheritance (20)

Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructors
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
OOP PPT 1.pptx
OOP PPT 1.pptxOOP PPT 1.pptx
OOP PPT 1.pptx
 
Intro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suIntro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the su
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Oop ppt
Oop pptOop ppt
Oop ppt
 
Python_Unit_2 OOPS.pptx
Python_Unit_2  OOPS.pptxPython_Unit_2  OOPS.pptx
Python_Unit_2 OOPS.pptx
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee class
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee class
 
class and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptxclass and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptx
 
Pythonclass
PythonclassPythonclass
Pythonclass
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
 
Iterative Methodology for Personalization Models Optimization
 Iterative Methodology for Personalization Models Optimization Iterative Methodology for Personalization Models Optimization
Iterative Methodology for Personalization Models Optimization
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 
Cell phone jammer
Cell phone jammerCell phone jammer
Cell phone jammer
 

Inheritance

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. CONTENTS • CLASS • OBJECT • INHERITANCE SINGLE INHERITANCE MULTIPLE INHERITANCE HIERARCHICAL INHERITANCE MULTILEVEL INHERITANCE HYBRID INHERITANS(Virtual Inheritance)
  • 5. CLASS • Class is the base design of objects means expanded concept of a data, that can hold both data and functions. • No memory is allocated when class is created. • It is a user defined data type. Example : A car is consider as a class Methods : Engine, wheels, steering. Properties : company, model, colour, speed, etc….
  • 6. OBJECT • Object is the instance of class, means identifiable entity with some characteristics and behaviour. • Memory allocated when only an object is created.
  • 7. INHERITANCE  Deriving new class from existing class.  Object of one class contains the property of another class.  Reusability.  We can add features to an existing class without modifying it.
  • 8. TYPES OF INHERITANCE • Single Inheritance • Hierarchical Inheritance • Multi Level Inheritance • Hybrid Inheritance • Multiple Inheritance
  • 9. SINGLE INHERITANCE • One derived class inherits from only one base class • Most simplest form of Inheritance.
  • 11. EXAMPLE #include<iostream> using namespace std; class father { public: string name; int age,pincode; }; class child:public father { public: string school; int standard; }; main() { father obj1; child obj2; cout<<"enter the name of father:"; cin>>obj1.name; cout<<"enter the age of father:"; cin>>obj1.age; cout<<"enter the pincode of father:"; cin>>obj1.pincode; cout<<"-------------DETAIL OF CHILD--------------n"; cout<<"enter the name of child:"; cin>>obj2.name; cout<<"enter the age of child:"; cin>>obj2.age; cout<<"enter the pincode of child:"; cin>>obj2.pincode; cout<<"enter the school name of child:"; cin>>obj2.school; cout<<"enter the standard of child:"; cin>>obj2.standard; }
  • 12.
  • 13. HEIRARCHICAL INHERITANCE • More than one derived classes is derived from common base class.
  • 15. EXAMPLE #include<iostream> using namespace std; class user { public: string name,place; int age; }; class student:public user { public: int rollno,classs,mark1,mark2; }; class teacher:public user { public: string department; int teacher_id,salary; }; main() { user obj; student obj1; teacher obj2; cout<<"-----------------STUDENT-------------n"; cout<<"enter the name:"; cin>>obj1.name; cout<<"enter the age:"; cin>>obj1.age; cout<<"enter the place:"; cin>>obj1.place; cout<<"enter the rollno:"; cin>>obj1.rollno; cout<<"enter the class:"; cin>>obj1.classs; cout<<"enter the mark1:"; cin>>obj1.mark1; cout<<"enter the mark2:"; cin>>obj1.mark2; cout<<"---------------TEACHER---------------n"; cout<<"enter the name:"; cin>>obj2.name; cout<<"enter the age:"; cin>>obj2.age; cout<<"enter the place:"; cin>>obj2.place; cout<<"enter the id:"; cin>>obj2.teacher_id; cout<<"enter the salary:"; cin>>obj2.salary; cout<<"enter the department:"; cin>>obj2.department; }
  • 16.
  • 17. MULTI LEVEL INHERITANCE • Derived class is derived from another derived class.
  • 19. EXAMPLE #include<iostream> using namespace std; class grandparent { public: void gshow() { cout<<"intelligent"; } }; class parent:public grandparent { public: void pshow() { cout<<"nhandsom"; } }; class child:public parent { public: void cshow() { cout<<"nobedience"; } }; main() { grandparent obj1; parent obj2; child obj3; cout<<"QUALITY OF GRANDPAn"; obj1.gshow(); cout<<"nQUALITIES OF FATHERn"; obj2.gshow(); obj2.pshow(); cout<<"nQUALITIES OF CHILDn"; obj3.gshow(); obj3.pshow(); obj3.cshow(); }
  • 20.
  • 21. HYBRID INHERITANCE • Combination of single Inheritance , hierarchical inheritance and multi level inheritance.
  • 23. EXAMPLE #include<iostream> using namespace std; class grandparent { public:void gshow() { cout<<"nintelligent"; } }; class parent:public grandparent { public: void pshow() { cout<<"neducated"; } }; class son:public parent { public: void sshow() { cout<<"nobedience"; } }; class daugter:public parent { public: void dshow() { cout<<"nbeautiful"; } }; main() { grandparent gobj; parent pobj; son sobj; daugter dobj; cout<<"QUALITY OF GRANDPA"; gobj.gshow(); cout<<"nQUALITY OF PARENT"; pobj.gshow(); pobj.pshow(); cout<<"nQUALITIES OF SON"; sobj.sshow(); sobj.pshow(); sobj.gshow(); cout<<"nQUALITIES OF DAUGHTER"; dobj.dshow(); dobj.pshow(); dobj.gshow(); }
  • 24.
  • 25. MULTIPLE INHERITANCE • Derived class is derived from more than one base class.
  • 27. EXAMPLE #include<iostream> using namespace std; class father { public: void fshow() { cout<<"discipline"; } }; class mother { public: void mshow() { cout<<"nopen minded"; } }; class child:public father,public mother { public: void cshow() { cout<<"nintelligent"; } }; main() { father obj1; mother obj2; child obj3; cout<<"QUALITY OF FATHERn"; obj1.fshow(); cout<<"n"; cout<<"nQUALITY OF MOTHER"; obj2.mshow(); cout<<"n"; cout<<"nQUALITIES OF CHILDn"; obj3.fshow(); obj3.mshow(); obj3.cshow(); }
  • 28.
  • 29. CONCLUSION We can REUSE the methods and data of the existing class We can EXTEND the existing class by adding new data and new methods We can MODIFY the existing class by overloading its methods with your own implementations
  • 30. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 31. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us