SlideShare a Scribd company logo
1 of 19
Topic :-Inheritance
Presented By:
Jinal Budheliya :170060107002
Nikit Dungarani :170060107008
Smit Savani :170060107053
Mayur Sharma :170060107054
Kaushik Sutariya :170060107059
Bhagwan Mahavir College of
Engineering and Technology
Guided By :Ms. Ridhdhi Naik
Subject :- .Net Technology(2160711)
Inheritance
 Inheritance is where one class (child class) inherits the properties of
another class (parent class).
 Inheritance is a mechanism of acquiring the features and behaviors
of a class by another class.
 The class whose members are inherited is called the base class, and
the class that inherits those members is called the derived class.
 Inheritance implements the IS-A relationship.
 Example
• “She had inherited the beauty of her mother”
Why Inheritance?
 Advantages of Inheritance
• Reduce code redundancy
• Provides code reusability
• Reduces source code size and improves code readability
• Code is easy to manage and divided into parent and child classes
Disadvantages - Inheritance
 In Inheritance base class and child classes are tightly coupled.
Hence If you change the code of parent class, it will get affects to
the all the child classes.
 In class hierarchy many data members remain unused and the
memory allocated to them is not utilized.
 Hence affect performance of your program if you have not
implemented inheritance correctly.
Different Types of Inheritance
Single Inheritance
Multi-level Inheritance
Multiple Inheritance
Multipath Inheritance
Hierarchical Inheritance
Hybrid Inheritance
Single Inheritance
Single Inheritance
In single inheritance, a derived
class is created from a single
base class.
Class A (Base)
Class B (Derived)
Example - Single Inheritance
//Base Class
class Teacher
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
//Derived Class
class Student : Teacher
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
class Program
{
static void Main(string[] args)
{
Teacher d = new Teacher();
d.Teach();
Student s = new Student();
s.Learn();
s.Teach();
Console.ReadKey();
}
}
Multi-level Inheritance
Multi-level
Inheritance
In Multi-level inheritance, a
derived class is created from
another derived class.
Class A (Base)
Class B
Class C
Example – Multi-Level Inheritance
//Base Class
class Teacher
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
//Base,Derived Class
class Student : Teacher
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
//Derived Class
class SemFour : Student
{
public void FourthSem()
{
Console.WriteLine("Semester
Four Students");
}
}
class Program
{
static void Main(string[] args)
{
Teacher d = new Teacher();
d.Teach();
Student s = new Student();
s.Learn();
s.Teach();
SemFour Sem = new SemFour();
Sem.Learn();
Sem.Teach();
Sem.FourthSem();
Console.ReadKey();
}
}
Cont..
Output :
Multiple Inheritance
Multiple Inheritance
 In Multiple inheritance, a derived class is created from more than
one base class.
 This inheritance is not supported by .NET Languages like C#, F#
etc.
Class A (Base) Class B (Base)
Class C
Example – Multiple Inheritance
//Base Class
class Teacher
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
//Base,Derived Class
class Student
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
//Derived Class
class SemFour : Student , Teacher
{
public void FourthSem()
{
Console.WriteLine("Semester
Four Students");
}
}
Multipath Inheritance
Multipath Inheritance
 In Multipath inheritance, a derived class is created from another
derived classes and the same base class of another derived
classes.
 This inheritance is not supported by .NET Languages like C#, F#
etc.
Class A
Class B Class C
Class D
Example – Multipath Inheritance
Hierarchical Inheritance
Class A
Class C Class B
Class D Class E Class F Class G
Example – Hierarchical Inheritance
Hybrid Inheritance
Class A
Class C Class B
Class D Class E
Class F
Example – Hybrid Inheritance
Inheritance

More Related Content

Similar to Inheritance

INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxDeepasCSE
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritanceIntro C# Book
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 
Inheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdfInheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdfkshitijsaini9
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfAnant240318
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In JavaManish Sahu
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaRahulAnanda1
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interfaceShubham Sharma
 
Multiple inheritance
Multiple inheritanceMultiple inheritance
Multiple inheritancezindadili
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdfWaqarRaj1
 

Similar to Inheritance (20)

Inheritance
InheritanceInheritance
Inheritance
 
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
29csharp
29csharp29csharp
29csharp
 
29c
29c29c
29c
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdfInheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdf
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdf
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 
Multiple inheritance
Multiple inheritanceMultiple inheritance
Multiple inheritance
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
INHERITANCE-Oopc ppt-ta4
INHERITANCE-Oopc ppt-ta4INHERITANCE-Oopc ppt-ta4
INHERITANCE-Oopc ppt-ta4
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 

Recently uploaded

Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxMohamed Rizk Khodair
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 

Recently uploaded (20)

Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 

Inheritance

  • 1. Topic :-Inheritance Presented By: Jinal Budheliya :170060107002 Nikit Dungarani :170060107008 Smit Savani :170060107053 Mayur Sharma :170060107054 Kaushik Sutariya :170060107059 Bhagwan Mahavir College of Engineering and Technology Guided By :Ms. Ridhdhi Naik Subject :- .Net Technology(2160711)
  • 2. Inheritance  Inheritance is where one class (child class) inherits the properties of another class (parent class).  Inheritance is a mechanism of acquiring the features and behaviors of a class by another class.  The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.  Inheritance implements the IS-A relationship.  Example • “She had inherited the beauty of her mother”
  • 3. Why Inheritance?  Advantages of Inheritance • Reduce code redundancy • Provides code reusability • Reduces source code size and improves code readability • Code is easy to manage and divided into parent and child classes
  • 4. Disadvantages - Inheritance  In Inheritance base class and child classes are tightly coupled. Hence If you change the code of parent class, it will get affects to the all the child classes.  In class hierarchy many data members remain unused and the memory allocated to them is not utilized.  Hence affect performance of your program if you have not implemented inheritance correctly.
  • 5. Different Types of Inheritance Single Inheritance Multi-level Inheritance Multiple Inheritance Multipath Inheritance Hierarchical Inheritance Hybrid Inheritance
  • 6. Single Inheritance Single Inheritance In single inheritance, a derived class is created from a single base class. Class A (Base) Class B (Derived)
  • 7. Example - Single Inheritance //Base Class class Teacher { public void Teach() { Console.WriteLine("Teach"); } } //Derived Class class Student : Teacher { public void Learn() { Console.WriteLine("Learn"); } } class Program { static void Main(string[] args) { Teacher d = new Teacher(); d.Teach(); Student s = new Student(); s.Learn(); s.Teach(); Console.ReadKey(); } }
  • 8. Multi-level Inheritance Multi-level Inheritance In Multi-level inheritance, a derived class is created from another derived class. Class A (Base) Class B Class C
  • 9. Example – Multi-Level Inheritance //Base Class class Teacher { public void Teach() { Console.WriteLine("Teach"); } } //Base,Derived Class class Student : Teacher { public void Learn() { Console.WriteLine("Learn"); } } //Derived Class class SemFour : Student { public void FourthSem() { Console.WriteLine("Semester Four Students"); } } class Program { static void Main(string[] args) { Teacher d = new Teacher(); d.Teach(); Student s = new Student(); s.Learn(); s.Teach(); SemFour Sem = new SemFour(); Sem.Learn(); Sem.Teach(); Sem.FourthSem(); Console.ReadKey(); } }
  • 11. Multiple Inheritance Multiple Inheritance  In Multiple inheritance, a derived class is created from more than one base class.  This inheritance is not supported by .NET Languages like C#, F# etc. Class A (Base) Class B (Base) Class C
  • 12. Example – Multiple Inheritance //Base Class class Teacher { public void Teach() { Console.WriteLine("Teach"); } } //Base,Derived Class class Student { public void Learn() { Console.WriteLine("Learn"); } } //Derived Class class SemFour : Student , Teacher { public void FourthSem() { Console.WriteLine("Semester Four Students"); } }
  • 13. Multipath Inheritance Multipath Inheritance  In Multipath inheritance, a derived class is created from another derived classes and the same base class of another derived classes.  This inheritance is not supported by .NET Languages like C#, F# etc. Class A Class B Class C Class D
  • 14. Example – Multipath Inheritance
  • 15. Hierarchical Inheritance Class A Class C Class B Class D Class E Class F Class G
  • 17. Hybrid Inheritance Class A Class C Class B Class D Class E Class F
  • 18. Example – Hybrid Inheritance