SlideShare a Scribd company logo
1 of 17
OOP Inheritance (Backbone of the OOP) Instructor Mr.Fasee Ullah CUSIT Peshawar
C++ and inheritance ,[object Object],[object Object],[object Object],[object Object]
What a derived class doesn't inherit ,[object Object]
What a derived class can add ,[object Object],[object Object],[object Object]
When a  derived-class object  is created & destroyed ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Advantages of inheritance ,[object Object],[object Object],[object Object],[object Object]
Access Rights of Derived Classes Type of Inheritance
Inheritance ,[object Object],This hierarchy could, of course, be continued for more levels. Each level inherits the attributes of the above level.  Shape is the base class.  2-D and 3-D are derived from Shape and Circle, Square, and Triangle are derived from 2-D.  Similarly, Sphere, Cube, and Tetrahedron are derived from 3-D.
Inheritance Concept Rectangle Triangle Polygon Point Circle 3D-Point
Parent and Child Classes   Inheritance Concept Rectangle Triangle Polygon class Polygon { private:   int width, length; public:   void set(int w, int l); } class Rectangle{ private:   int width, length; public:   void set(int w, int l);   int area(); } class Triangle{ private:   int width, length; public:   void set(int w, int l);   int area(); }
Inheritance Concept Rectangle Triangle Polygon class Polygon { protected:   int width, length; public:   void set(int w, int l); } class Rectangle : public Polygon { public: int area(); } class Rectangle{ protected:   int width, length; public:   void set(int w, int l);   int area(); }
Inheritance Concept Rectangle Triangle Polygon class Polygon { protected:   int width, length; public:   void set(int w, int l); } class Triangle : public Polygon { public: int area(); } class Triangle : public polygon{ protected:   int width, length; public:   void set(int w, int l);   int area(); }
Inheritance Concept Point Circle 3D-Point class Point { protected:   int x, y; public:   void set(int a, int b); } class Circle : public Point { private:  double r; } class 3D-Point: public Point { private:  int z; } x y x y r x y z
Example1 on Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example2 on Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example3 on Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],void getradius(int r) { radius=r; } void area(){ int area; area=3.142*radius*radius; cout<<&quot;Area of circle is &quot;<<area; } }; void main(){ circle c; c.getxy(3,5); c.getradius(5); c.area(); getch(); }
Assignment #2 ,[object Object],[object Object]

More Related Content

What's hot (20)

EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
inheritance
inheritanceinheritance
inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to Inheritance
 

Similar to Inheritance (20)

Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 
Multiple file programs, inheritance, templates
Multiple file programs, inheritance, templatesMultiple file programs, inheritance, templates
Multiple file programs, inheritance, templates
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritance
 
Inheritance (1)
Inheritance (1)Inheritance (1)
Inheritance (1)
 
Segundo avance
Segundo avanceSegundo avance
Segundo avance
 
RajLec10.ppt
RajLec10.pptRajLec10.ppt
RajLec10.ppt
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Oops concept
Oops conceptOops concept
Oops concept
 
Inheritance
InheritanceInheritance
Inheritance
 
6 Inheritance
6 Inheritance6 Inheritance
6 Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Inheritance
Inheritance Inheritance
Inheritance
 
Topic6inheritanceAndPolymorphism.ppt
Topic6inheritanceAndPolymorphism.pptTopic6inheritanceAndPolymorphism.ppt
Topic6inheritanceAndPolymorphism.ppt
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Java02
Java02Java02
Java02
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 

Inheritance

  • 1. OOP Inheritance (Backbone of the OOP) Instructor Mr.Fasee Ullah CUSIT Peshawar
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Access Rights of Derived Classes Type of Inheritance
  • 8.
  • 9. Inheritance Concept Rectangle Triangle Polygon Point Circle 3D-Point
  • 10. Parent and Child Classes Inheritance Concept Rectangle Triangle Polygon class Polygon { private: int width, length; public: void set(int w, int l); } class Rectangle{ private: int width, length; public: void set(int w, int l); int area(); } class Triangle{ private: int width, length; public: void set(int w, int l); int area(); }
  • 11. Inheritance Concept Rectangle Triangle Polygon class Polygon { protected: int width, length; public: void set(int w, int l); } class Rectangle : public Polygon { public: int area(); } class Rectangle{ protected: int width, length; public: void set(int w, int l); int area(); }
  • 12. Inheritance Concept Rectangle Triangle Polygon class Polygon { protected: int width, length; public: void set(int w, int l); } class Triangle : public Polygon { public: int area(); } class Triangle : public polygon{ protected: int width, length; public: void set(int w, int l); int area(); }
  • 13. Inheritance Concept Point Circle 3D-Point class Point { protected: int x, y; public: void set(int a, int b); } class Circle : public Point { private: double r; } class 3D-Point: public Point { private: int z; } x y x y r x y z
  • 14.
  • 15.
  • 16.
  • 17.