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

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
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
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
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
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
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
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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
 
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...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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.
 

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; }