SlideShare a Scribd company logo
1 of 16
Inheritance
Presented by :
Dilan Abdulilah Abdullah
Kevi Shemdin Jamil
Content
 What is Inheritance
 Important terminology
 How to perform
inheritance
 Types of Inheritance
 Advantages of
inheritance
 Conclusion
Inheritance
 In C# , inheritance allows us to create a new class from an
existing class. It is a key feature of Object-Oriented
Programming (OOP). The derived class or The child class will
inherit fields and methods all the public and protected
properties of the base class or also known as parent class In
addition, it can have its own properties and methods. This helps
with the code reusability in C#.
Important terminology:
Super Class: Sub Class:
The class that inherits the
other class is known as
subclass
Reusability:
• Inheritance supports the concept
of “reusability”, I.e. when we
want to create a new class and
there is already a class that
includes some of the code that
we want, we can derive our new
class from the existing class.
Is a Relationship:
We use inheritance only if
there is an is-a
relationship between two
classes.
The class whose features
are inherited is known as
super class
Syntax :
class derived-class : base-class
{
// methods and fields
.
.
}
How to Perform Inheritance in c#
Types of Inheritance
01
Single
Inheritance
03
Hierarchal
inheritance
02
Multilevel
Inheritance
● In single inheritance, subclasses
inherit the features of one
superclass. In image below, the
class A serves as a base class for
the derived class B.
Single Inheritance
class Fruit
{
public void Display()
{
Console.WriteLine("Fruit");
}
}
//Our derived class is Bananna and is declared
below −
class Banana : Fruit
{
public void DisplayOne()
{
Console.WriteLine("Banana is Fruit ");
}
}
Single Inheritance
In multilevel
inheritance, a derived
class inherits from a
base and then the
same derived class
acts as a base class
for another class.
Multilevel inheritance
Example About Multilevel
Inheritance:
In the preceding program, each
class is derived from one class
that is derived from another class
hence this type of inheritance is
called Multilevel Inheritance.
class Fruit
{
public void Display()
{
Console.WriteLine("Fruit");
}
}
//Our derived class is Bananna and is declared
below −
class Banana : Fruit
{
public void DisplayOne()
{
Console.WriteLine("Banana is Fruit ");
}
}
Multilevel inheritance
In hierarchical inheritance,
multiple derived classes inherit
from a single base class.
Hierarchal
inheritance
In the preceding program one base class is
derived in many classes hence it is a called
a Hierarchical Inheritance
Example About Hierarchal
Inheritance
class Fruit
{
public void Display()
{
Console.WriteLine("Fruit");
}
}
//Our derived class is Bananna and is declared
below −
class Banana : Fruit
{
public void DisplayOne()
{
Console.WriteLine("Banana is Fruit ");
}
}
Multilevel inheritance
Advantages of inheritance
 It helps in using the same code again means code reusability.
 It reduces code redundancy.
 It helps in reading the code more comfortably.
 It also reduces the size of the source code and file.
 It helps in providing the extensibility to code.
 Private members are not accessed in derived class when base class
members are inherited by the derived class.
 The code is easy to manage as it divided into classes of the base
class and child class.
Thanks!

More Related Content

Similar to Programming Lesson by Slidesgo.pptx

Similar to Programming Lesson by Slidesgo.pptx (20)

Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance
InheritanceInheritance
Inheritance
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Lec5.ppt
Lec5.pptLec5.ppt
Lec5.ppt
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Inheritance
InheritanceInheritance
Inheritance
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
 
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 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)
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 

More from DilanAlmsa

Stakeholder Infographics by Slidesgo.pptx
Stakeholder Infographics by Slidesgo.pptxStakeholder Infographics by Slidesgo.pptx
Stakeholder Infographics by Slidesgo.pptxDilanAlmsa
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.pptDilanAlmsa
 
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptxDilanAlmsa
 
lecture1-2023.pptx
lecture1-2023.pptxlecture1-2023.pptx
lecture1-2023.pptxDilanAlmsa
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptxDilanAlmsa
 
Java22_1670144363.pptx
Java22_1670144363.pptxJava22_1670144363.pptx
Java22_1670144363.pptxDilanAlmsa
 

More from DilanAlmsa (6)

Stakeholder Infographics by Slidesgo.pptx
Stakeholder Infographics by Slidesgo.pptxStakeholder Infographics by Slidesgo.pptx
Stakeholder Infographics by Slidesgo.pptx
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
 
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptx
 
lecture1-2023.pptx
lecture1-2023.pptxlecture1-2023.pptx
lecture1-2023.pptx
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptx
 
Java22_1670144363.pptx
Java22_1670144363.pptxJava22_1670144363.pptx
Java22_1670144363.pptx
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Programming Lesson by Slidesgo.pptx

  • 1. Inheritance Presented by : Dilan Abdulilah Abdullah Kevi Shemdin Jamil
  • 2. Content  What is Inheritance  Important terminology  How to perform inheritance  Types of Inheritance  Advantages of inheritance  Conclusion
  • 3. Inheritance  In C# , inheritance allows us to create a new class from an existing class. It is a key feature of Object-Oriented Programming (OOP). The derived class or The child class will inherit fields and methods all the public and protected properties of the base class or also known as parent class In addition, it can have its own properties and methods. This helps with the code reusability in C#.
  • 4. Important terminology: Super Class: Sub Class: The class that inherits the other class is known as subclass Reusability: • Inheritance supports the concept of “reusability”, I.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. Is a Relationship: We use inheritance only if there is an is-a relationship between two classes. The class whose features are inherited is known as super class
  • 5. Syntax : class derived-class : base-class { // methods and fields . . } How to Perform Inheritance in c#
  • 7. ● In single inheritance, subclasses inherit the features of one superclass. In image below, the class A serves as a base class for the derived class B. Single Inheritance
  • 8. class Fruit { public void Display() { Console.WriteLine("Fruit"); } } //Our derived class is Bananna and is declared below − class Banana : Fruit { public void DisplayOne() { Console.WriteLine("Banana is Fruit "); } } Single Inheritance
  • 9. In multilevel inheritance, a derived class inherits from a base and then the same derived class acts as a base class for another class. Multilevel inheritance
  • 10. Example About Multilevel Inheritance: In the preceding program, each class is derived from one class that is derived from another class hence this type of inheritance is called Multilevel Inheritance.
  • 11. class Fruit { public void Display() { Console.WriteLine("Fruit"); } } //Our derived class is Bananna and is declared below − class Banana : Fruit { public void DisplayOne() { Console.WriteLine("Banana is Fruit "); } } Multilevel inheritance
  • 12. In hierarchical inheritance, multiple derived classes inherit from a single base class. Hierarchal inheritance
  • 13. In the preceding program one base class is derived in many classes hence it is a called a Hierarchical Inheritance Example About Hierarchal Inheritance
  • 14. class Fruit { public void Display() { Console.WriteLine("Fruit"); } } //Our derived class is Bananna and is declared below − class Banana : Fruit { public void DisplayOne() { Console.WriteLine("Banana is Fruit "); } } Multilevel inheritance
  • 15. Advantages of inheritance  It helps in using the same code again means code reusability.  It reduces code redundancy.  It helps in reading the code more comfortably.  It also reduces the size of the source code and file.  It helps in providing the extensibility to code.  Private members are not accessed in derived class when base class members are inherited by the derived class.  The code is easy to manage as it divided into classes of the base class and child class.