SlideShare a Scribd company logo
1 of 32
INHERITANCE
Inheritance is the ability of one class to inherit the  properties of another class. A new class can be created from an existing class.  The existing class is called the Base class or Super class and the new class  is called  the Derived class or Sub-class. e.g: Car inherits from another class auto-mobile. Science student inherits from class student
Advantages of Inheritance: Reusability of code  Size of the code is reduced. Transitivity: 	If  B is derived from A and C is derived from B      then C is also derived from A.
Person  -   Base Class Student -  Derived class
QUADRILATERAL SQUARE                       RECTANGLE                      RHOMBUS
Identify the type of  inheritance: 2009 DELHI class FacetoFace {       char CenterCode[10];   public:       void Input();        void Output()    }; class Online {        char website[50];       public:     void SiteIn();     void SiteOut();      };
class Training : public  FacetoFace, private Online { 	long Tcode; 	float Charge; int Period;       public:               void Register();               void Show(); }; :
Base Classes: FacetoFace          Online Derived Class: Training Multiple base classes   so    multiple inheritance
Delhi Class Dolls { 	char Dcode[5];    protected:      float price;      void CalcPrice(float); Public:     Dolls();     void Dinput();     void Dshow(); };
class  SoftDolls: public Dolls {       char SDName[20];        float Weight; public: SoftDolls();        void SDInput();        void SDShow(); }; class ElectronicDolls:  public Dolls {       char EDName[20];       char BatteryType[10]; int Batteries;  public: ElectronicDolls();        void EDInput();        void EDShow(); };
BASE CLASS:   DOLLS ElectronicDolls SoftDolls HIERARCHICAL INHERITANCE
Out-side Delhi 2006 class furniture  {        char Type;       char Model[10];     public:       furniture();     void Read_fur_Details();     void Disp_fur_Details();    }; class Sofa : public furniture { intno_of_seats;     float cost_of_sofa; public:    void Read_sofa_details();    void Disp_sofa_details(); };
class office : private  Sofa { intno_of_pieces;        char Delivery_date[10];     public:    void Read_office_details();    void Disp_office_details(); }; Void main() {      office MyFurniture; }
Furniture Sofa office Sofa is derived from furniture Office is derived from sofa. Multi-level Inheritance
Visibility Modes It can be public, private or protected. The private data of base class cannot be inherited. (i) If inheritance is done in public mode, public members of the base class become the public members of derived class and protected members of base class become the protected members of derived class. (ii) If inheritance is done in a private mode, public and protected members of  base class become the private members of derived class. (iii) If inheritance is done in a protected mode, public and protected members of base class become the protected members of derived class.
Accessibility of Base Class members:
#include<iostream.h> class one { int a;   // only for class members 	 protected: int b;    // for class members and derived classes 	 public: int c;   // for class members, derived classes, main 	 one() 	 { 		  a=3; 		  b=5; 		  c=10; 		  } 	  void show() 	  { cout<<a<<":"<<b<<":"<<c<<endl; 		 } 		 };
	 class two :public one 	 { int p; 		  public: 		  two() 		  { 				p=25; 				} 		  void show1() 		  { cout<<a<<endl;   error.  Not accessible cout<<b<<endl; o.k. cout<<c<<endl; o.k. 			  } 			  };
class three : public two 	 { int x; 			public : 			three() 			{ 				x=100; 				} 				void show2() 				{ cout<<x<<endl; o.k. cout<<p<<endl; error. Not accessible cout<<b<<endl; o.k. cout<<c<<endl; o.k. 					} 					};
int main() 		{ 				three ob; cout<<ob.c<<endl; o.k. public member cout<<ob.b<<endl;  error.  Not available ob.show(); 				ob.show1(); 				ob.show2(); 				return 0;                                                                }
#include<iostream.h> class one { int a;   // only for class members 	 protected: int b;    // for class members and derived classes 	 public: int c;   // for class members, derived classes,main 	 one() 	 { 		  a=3; 		  b=5; 		  c=10; 		  } 	  void show() 	  { cout<<a<<":"<<b<<":"<<c<<endl; 		 } 		 };
class two :protected one 	 { int p; 		  public: 		  two() 		  { 				p=25; 				} 		  void show1() 		  { cout<<a<<endl;  // error.  Not accessible cout<<b<<endl; // o.k. protected cout<<c<<endl; // o.k. becomes protected 			  } 			  };
class three : protected  two 	 { int x; 			public : 			three() 			{ 				x=100; 				} 				void show2() 				{ cout<<x<<endl; // o.k. its own member				cout<<p<<endl; // error. Not accessible cout<<b<<endl; // o.k. protected				cout<<c<<endl; // o.k. has become protected 					} 					};
int main() 			{ 			three ob; cout<<ob.c<<endl; // error has become protected not available cout<<ob.b<<endl; // error.  Not available   				ob.show();   // error.  Has become protected not available 	ob.show1();  // error.  Has become protected not available  	ob.show2(); // O.K. 	return 0; 				}
#include<iostream.h> class one { int a;   // only for class members 	 protected: int b;    // for class members and derived classes 	 public: int c;   // for class members, derived classes, main 	 one() 	 { 		  a=3; 		  b=5; 		  c=10; 		  } 	  void show() 	  { cout<<a<<":"<<b<<":"<<c<<endl; 		 } 		 };
	 class two :private  one 	 { int p; 		  public: 		  two() 		  { 				p=25; 				} 		  void show1() 		  { cout<<p<<endl; // o.k. its own member cout<<a<<endl;  // error.  Not accessible cout<<b<<endl; // error.  has become private . cout<<c<<endl; // error .  has become private 						  } 			  };
class three : private   two 	 { int x; 			public : 			three() 			{ 			x=100; 				} 		void show2() 				{					cout<<x<<endl; // o.k. its own member cout<<p<<endl; // error. Not accessible				cout<<b<<endl; // error.  not available cout<<c<<endl; // error. not available 					} 				};
int main() 			{			three ob; cout<<ob.c<<endl; // error not available		cout<<ob.b<<endl; // error.  Not available		ob.show();   // error.   not available			ob.show1();  // error . not available			ob.show2(); // o.k. its own member			return 0; 				}

More Related Content

What's hot

friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#foreverredpb
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Access specifier
Access specifierAccess specifier
Access specifierzindadili
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Paumil Patel
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of ConstructorsDhrumil Panchal
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++ NikitaKaur10
 

What's hot (20)

friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
Access specifier
Access specifierAccess specifier
Access specifier
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Abstract class
Abstract classAbstract class
Abstract class
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
 

Viewers also liked

Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop pptdaxesh chauhan
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...cprogrammings
 

Viewers also liked (6)

Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
encapsulation
encapsulationencapsulation
encapsulation
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Inheritance
InheritanceInheritance
Inheritance
 

Similar to inheritance c++

chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdfstudy material
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphismFALLEE31188
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxurvashipundir04
 
Inheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridInheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridVGaneshKarthikeyan
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optdeepakskb2013
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesVinay Kumar
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming conceptsGanesh Karthik
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmersMark Whitaker
 
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Abu Saleh
 

Similar to inheritance c++ (20)

inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
Inheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridInheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybrid
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modes
 
Inheritance
InheritanceInheritance
Inheritance
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
 
Lab3
Lab3Lab3
Lab3
 
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
 

Recently uploaded

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

inheritance c++

  • 2. Inheritance is the ability of one class to inherit the properties of another class. A new class can be created from an existing class. The existing class is called the Base class or Super class and the new class is called the Derived class or Sub-class. e.g: Car inherits from another class auto-mobile. Science student inherits from class student
  • 3. Advantages of Inheritance: Reusability of code Size of the code is reduced. Transitivity: If B is derived from A and C is derived from B then C is also derived from A.
  • 4. Person - Base Class Student - Derived class
  • 5.
  • 6.
  • 7. QUADRILATERAL SQUARE RECTANGLE RHOMBUS
  • 8.
  • 9.
  • 10. Identify the type of inheritance: 2009 DELHI class FacetoFace { char CenterCode[10]; public: void Input(); void Output() }; class Online { char website[50]; public: void SiteIn(); void SiteOut(); };
  • 11. class Training : public FacetoFace, private Online { long Tcode; float Charge; int Period; public: void Register(); void Show(); }; :
  • 12. Base Classes: FacetoFace Online Derived Class: Training Multiple base classes so multiple inheritance
  • 13. Delhi Class Dolls { char Dcode[5]; protected: float price; void CalcPrice(float); Public: Dolls(); void Dinput(); void Dshow(); };
  • 14. class SoftDolls: public Dolls { char SDName[20]; float Weight; public: SoftDolls(); void SDInput(); void SDShow(); }; class ElectronicDolls: public Dolls { char EDName[20]; char BatteryType[10]; int Batteries; public: ElectronicDolls(); void EDInput(); void EDShow(); };
  • 15. BASE CLASS: DOLLS ElectronicDolls SoftDolls HIERARCHICAL INHERITANCE
  • 16. Out-side Delhi 2006 class furniture { char Type; char Model[10]; public: furniture(); void Read_fur_Details(); void Disp_fur_Details(); }; class Sofa : public furniture { intno_of_seats; float cost_of_sofa; public: void Read_sofa_details(); void Disp_sofa_details(); };
  • 17. class office : private Sofa { intno_of_pieces; char Delivery_date[10]; public: void Read_office_details(); void Disp_office_details(); }; Void main() { office MyFurniture; }
  • 18. Furniture Sofa office Sofa is derived from furniture Office is derived from sofa. Multi-level Inheritance
  • 19. Visibility Modes It can be public, private or protected. The private data of base class cannot be inherited. (i) If inheritance is done in public mode, public members of the base class become the public members of derived class and protected members of base class become the protected members of derived class. (ii) If inheritance is done in a private mode, public and protected members of base class become the private members of derived class. (iii) If inheritance is done in a protected mode, public and protected members of base class become the protected members of derived class.
  • 20. Accessibility of Base Class members:
  • 21. #include<iostream.h> class one { int a; // only for class members protected: int b; // for class members and derived classes public: int c; // for class members, derived classes, main one() { a=3; b=5; c=10; } void show() { cout<<a<<":"<<b<<":"<<c<<endl; } };
  • 22. class two :public one { int p; public: two() { p=25; } void show1() { cout<<a<<endl; error. Not accessible cout<<b<<endl; o.k. cout<<c<<endl; o.k. } };
  • 23. class three : public two { int x; public : three() { x=100; } void show2() { cout<<x<<endl; o.k. cout<<p<<endl; error. Not accessible cout<<b<<endl; o.k. cout<<c<<endl; o.k. } };
  • 24. int main() { three ob; cout<<ob.c<<endl; o.k. public member cout<<ob.b<<endl; error. Not available ob.show(); ob.show1(); ob.show2(); return 0; }
  • 25. #include<iostream.h> class one { int a; // only for class members protected: int b; // for class members and derived classes public: int c; // for class members, derived classes,main one() { a=3; b=5; c=10; } void show() { cout<<a<<":"<<b<<":"<<c<<endl; } };
  • 26. class two :protected one { int p; public: two() { p=25; } void show1() { cout<<a<<endl; // error. Not accessible cout<<b<<endl; // o.k. protected cout<<c<<endl; // o.k. becomes protected } };
  • 27. class three : protected two { int x; public : three() { x=100; } void show2() { cout<<x<<endl; // o.k. its own member cout<<p<<endl; // error. Not accessible cout<<b<<endl; // o.k. protected cout<<c<<endl; // o.k. has become protected } };
  • 28. int main() { three ob; cout<<ob.c<<endl; // error has become protected not available cout<<ob.b<<endl; // error. Not available ob.show(); // error. Has become protected not available ob.show1(); // error. Has become protected not available ob.show2(); // O.K. return 0; }
  • 29. #include<iostream.h> class one { int a; // only for class members protected: int b; // for class members and derived classes public: int c; // for class members, derived classes, main one() { a=3; b=5; c=10; } void show() { cout<<a<<":"<<b<<":"<<c<<endl; } };
  • 30. class two :private one { int p; public: two() { p=25; } void show1() { cout<<p<<endl; // o.k. its own member cout<<a<<endl; // error. Not accessible cout<<b<<endl; // error. has become private . cout<<c<<endl; // error . has become private } };
  • 31. class three : private two { int x; public : three() { x=100; } void show2() { cout<<x<<endl; // o.k. its own member cout<<p<<endl; // error. Not accessible cout<<b<<endl; // error. not available cout<<c<<endl; // error. not available } };
  • 32. int main() { three ob; cout<<ob.c<<endl; // error not available cout<<ob.b<<endl; // error. Not available ob.show(); // error. not available ob.show1(); // error . not available ob.show2(); // o.k. its own member return 0; }