SlideShare a Scribd company logo
1 of 11
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 1
Inheritance
CIS 2403
Object Oriented Programming
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 2
Association
Program Class instantiates in the Main methods
an object one from the Movie class
Until now …. Only Association
Progam
Main()
one
Name: Argo
length: 90
director: Lamont Johnson
Movie()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 3
Inheritance
Inheritance
= your object’s family tree
 used to avoid duplicate
code
 to save time in coding
 to reduce chances of
errors
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 4
Inheritance
Important terms:
– Base class: class used as the
basis for inheritance (Vehicle)
– Base class = superclass
= parent class
– Derived class: a class that
inherits form a base class
– Derived class = extended class
= subclass
= child class
– Ancestors = entire list of parent
classes
– Descendants = entire list of child
classes
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 5
Inheritance
 Use extends to inherit from a base class!
 The arrow stands for inheritance!
Person
firstName: string
lastName: string
Person()
Display()
PartTime
room: string
PartTime()
Display()
Employee
empNumber: int
empName: string
empHours:double
Employee()
Pay()
PartTime
hourlyRate: int
PartTime()
Pay()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 6
Inheritance
Methods can be overriden by the subclass
 use virtual (parent class) and override (child class)
Person
firstName: string
lastName: string
Person()
Pay()
Faculty
room: string
Faculty()
Pay()
Employee
empNumber: int
empName: string
empHours:double
Employee()
Pay()
PartTime
hourlyRate: int
PartTime()
Pay()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 7
Inheritance
Constructors
 when the base class has a constructor, your subclass
needs one, too.
 use super to connect to base class constructor
Employee
empNumber: int
empName: string
empHours:double
Employee()
Pay()
PartTime
hourlyRate: int
PartTime()
Pay()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 8
Inheritance
 Access Modifier: protected
 Can be accessed in the class and in the
sub class
Person
firstName: string
lastName: string
Person()
Display()
Faculty
room: string
Faculty()
Display()
Employee
empNumber: int
empName: string
empHours:double
Employee()
Pay()
PartTime
hourlyRate: int
PartTime()
Pay()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 9
Accessing the base class
The Super Keyword
 Sometimes you want to use the parent
class method that is overriden by the
child class method
 Use the keyword “super” for accessing
the base Class method
 Example: base.Display()
Person
firstName: string
lastName: string
Person()
Display()
Faculty
room: string
Faculty()
Display()
Employee
empNumber: int
empName: string
empHours:double
Employee()
Pay()
PartTime
hourlyRate: int
PartTime()
Pay()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 10
Abstract Class
Abstract class
 a class that is never instantiated
 you must create a subclass that
inherits from the superclass
 abstract classes have abstract
members that the derived class must
override to provide functionality
Person
firstName: string
lastName: string
Person()
Display()
Faculty
room: string
Faculty()
Display()
Employee
empNumber: int
empName: string
empHours:double
Employee()
Pay()
PartTime
hourlyRate: int
PartTime()
Pay()
ITDP 106 - Information Technology Essentials Elke Vogel-Adham 11
Abstract Class
Abstract class  ExampleVehicle
Price: double
Year: int
Vehicle ()
showDetail()
Car
EngineSize: double
Car()
showDetail()

More Related Content

Similar to 4 oo inheritance in c# (1)

inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPMPKKArc
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerCalvin French-Owen
 
Introduction to Actionscript3
Introduction to Actionscript3Introduction to Actionscript3
Introduction to Actionscript3Yoss Cohen
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSencha
 
AMF Testing Made Easy! DeepSec 2012
AMF Testing Made Easy! DeepSec 2012AMF Testing Made Easy! DeepSec 2012
AMF Testing Made Easy! DeepSec 2012Luca Carettoni
 
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNetAlex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNetAI Frontiers
 
Linux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OLinux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OYourHelper1
 
core java material.pdf
core java material.pdfcore java material.pdf
core java material.pdfRasa72
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plusSayed Ahmed
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Sayed Ahmed
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Scaling Deep Learning with MXNet
Scaling Deep Learning with MXNetScaling Deep Learning with MXNet
Scaling Deep Learning with MXNetAI Frontiers
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)Netcetera
 
Eclipse Modeling Framework
Eclipse Modeling FrameworkEclipse Modeling Framework
Eclipse Modeling FrameworkAjay K
 
Machine learning the next revolution or just another hype
Machine learning   the next revolution or just another hypeMachine learning   the next revolution or just another hype
Machine learning the next revolution or just another hypeJorge Ferrer
 
Polymorphism and Virtual Functions ppt bioinformatics
Polymorphism and Virtual Functions ppt bioinformaticsPolymorphism and Virtual Functions ppt bioinformatics
Polymorphism and Virtual Functions ppt bioinformaticsPriyanshuMittal31
 

Similar to 4 oo inheritance in c# (1) (20)

inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPM
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
 
Introduction to Actionscript3
Introduction to Actionscript3Introduction to Actionscript3
Introduction to Actionscript3
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
 
AMF Testing Made Easy! DeepSec 2012
AMF Testing Made Easy! DeepSec 2012AMF Testing Made Easy! DeepSec 2012
AMF Testing Made Easy! DeepSec 2012
 
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNetAlex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
Alex Smola at AI Frontiers: Scalable Deep Learning Using MXNet
 
Linux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OLinux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/O
 
core java material.pdf
core java material.pdfcore java material.pdf
core java material.pdf
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
Scaling Deep Learning with MXNet
Scaling Deep Learning with MXNetScaling Deep Learning with MXNet
Scaling Deep Learning with MXNet
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
 
L04 Software Design 2
L04 Software Design 2L04 Software Design 2
L04 Software Design 2
 
Eclipse Modeling Framework
Eclipse Modeling FrameworkEclipse Modeling Framework
Eclipse Modeling Framework
 
Machine learning the next revolution or just another hype
Machine learning   the next revolution or just another hypeMachine learning   the next revolution or just another hype
Machine learning the next revolution or just another hype
 
Bol.com
Bol.comBol.com
Bol.com
 
Polymorphism and Virtual Functions ppt bioinformatics
Polymorphism and Virtual Functions ppt bioinformaticsPolymorphism and Virtual Functions ppt bioinformatics
Polymorphism and Virtual Functions ppt bioinformatics
 

More from abdullah619

More from abdullah619 (11)

Testing chapter updated (1)
Testing chapter updated (1)Testing chapter updated (1)
Testing chapter updated (1)
 
Queue
QueueQueue
Queue
 
Stacks
StacksStacks
Stacks
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Lists
Lists Lists
Lists
 
Collections (1)
Collections (1)Collections (1)
Collections (1)
 
Exception handling
Exception handlingException handling
Exception handling
 
Polumorphism
PolumorphismPolumorphism
Polumorphism
 
Abstrcation
AbstrcationAbstrcation
Abstrcation
 
Methods in c# (1)
Methods in c# (1)Methods in c# (1)
Methods in c# (1)
 
5. linked list
5. linked list5. linked list
5. linked list
 

Recently uploaded

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 

Recently uploaded (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

4 oo inheritance in c# (1)

  • 1. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 1 Inheritance CIS 2403 Object Oriented Programming
  • 2. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 2 Association Program Class instantiates in the Main methods an object one from the Movie class Until now …. Only Association Progam Main() one Name: Argo length: 90 director: Lamont Johnson Movie()
  • 3. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 3 Inheritance Inheritance = your object’s family tree  used to avoid duplicate code  to save time in coding  to reduce chances of errors
  • 4. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 4 Inheritance Important terms: – Base class: class used as the basis for inheritance (Vehicle) – Base class = superclass = parent class – Derived class: a class that inherits form a base class – Derived class = extended class = subclass = child class – Ancestors = entire list of parent classes – Descendants = entire list of child classes
  • 5. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 5 Inheritance  Use extends to inherit from a base class!  The arrow stands for inheritance! Person firstName: string lastName: string Person() Display() PartTime room: string PartTime() Display() Employee empNumber: int empName: string empHours:double Employee() Pay() PartTime hourlyRate: int PartTime() Pay()
  • 6. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 6 Inheritance Methods can be overriden by the subclass  use virtual (parent class) and override (child class) Person firstName: string lastName: string Person() Pay() Faculty room: string Faculty() Pay() Employee empNumber: int empName: string empHours:double Employee() Pay() PartTime hourlyRate: int PartTime() Pay()
  • 7. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 7 Inheritance Constructors  when the base class has a constructor, your subclass needs one, too.  use super to connect to base class constructor Employee empNumber: int empName: string empHours:double Employee() Pay() PartTime hourlyRate: int PartTime() Pay()
  • 8. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 8 Inheritance  Access Modifier: protected  Can be accessed in the class and in the sub class Person firstName: string lastName: string Person() Display() Faculty room: string Faculty() Display() Employee empNumber: int empName: string empHours:double Employee() Pay() PartTime hourlyRate: int PartTime() Pay()
  • 9. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 9 Accessing the base class The Super Keyword  Sometimes you want to use the parent class method that is overriden by the child class method  Use the keyword “super” for accessing the base Class method  Example: base.Display() Person firstName: string lastName: string Person() Display() Faculty room: string Faculty() Display() Employee empNumber: int empName: string empHours:double Employee() Pay() PartTime hourlyRate: int PartTime() Pay()
  • 10. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 10 Abstract Class Abstract class  a class that is never instantiated  you must create a subclass that inherits from the superclass  abstract classes have abstract members that the derived class must override to provide functionality Person firstName: string lastName: string Person() Display() Faculty room: string Faculty() Display() Employee empNumber: int empName: string empHours:double Employee() Pay() PartTime hourlyRate: int PartTime() Pay()
  • 11. ITDP 106 - Information Technology Essentials Elke Vogel-Adham 11 Abstract Class Abstract class  ExampleVehicle Price: double Year: int Vehicle () showDetail() Car EngineSize: double Car() showDetail()