SlideShare ist ein Scribd-Unternehmen logo
1 von 27
C++ OOP :: Inheritance 14/10/2009 1 Hadziq Fabroyir - Informatics ITS
Classes Characteristic Classes are used to accomplish: Modularity► Scope for global (static) methods Blueprints for generating objects or instances Classes support  Data encapsulation - private data and implementation. Inheritance-code reuse 14/10/2009 Hadziq Fabroyir - Informatics ITS 2
Inheritance Inheritance allows a software developer to derive a new class from an existing one. 14/10/2009 Hadziq Fabroyir - Informatics ITS 3
Inheritance The existing class is called the parent, super, or baseclass. The derived class is called a child or subclass. 14/10/2009 Hadziq Fabroyir - Informatics ITS 4
Inheritance ,[object Object]
 The child has special rights to the parents methods and data.
Public access like any one else
Protected access available only to child classes (and their descendants).
The child has its own unique behaviors and data.14/10/2009 Hadziq Fabroyir - Informatics ITS 5
Inheritance Inheritance relationships are often shown graphically in a classdiagram with the arrow pointing to the parent class. Inheritance should create an is-arelationship, meaning the child is a more specific version of the parent. 14/10/2009 Hadziq Fabroyir - Informatics ITS 6 Animal Bird
Examples: Base Classes and Derived Classes 14/10/2009 Hadziq Fabroyir - Informatics ITS 7
Single / Multiple Inheritance ? Some languages, e.g., C++, allowMultiple inheritance, which allows a class to be derived from two or more classes, inheriting the members of all parents. C# and Java support only Single inheritance, meaning that a derived class can have only one parent class. 14/10/2009 Hadziq Fabroyir - Informatics ITS 8
Class Hierarchies A child class of one parent can be the parent of another child, forming a class hierarchy 14/10/2009 Hadziq Fabroyir - Informatics ITS 9
Classify It ! 14/10/2009 Hadziq Fabroyir - Informatics ITS 10
Class Hierarchies 14/10/2009 Hadziq Fabroyir - Informatics ITS 11
Classify It ! 14/10/2009 Hadziq Fabroyir - Informatics ITS 12
Class Hierarchies 14/10/2009 Hadziq Fabroyir - Informatics ITS 13
Class Hierarchies An inherited member is continually passed down the line Inheritance is transitive Good class design puts all common features as high in the hierarchy as is reasonable. Avoids redundant code. 14/10/2009 Hadziq Fabroyir - Informatics ITS 14
References and Inheritance An object reference can refer to an object of its class, or to an object of any class derived from it by inheritance. For example, if the 2DShape class is used to derive a child class called Triangle, then a 2DShape reference can be used to point to a Triangle object. 2DShape myShape; myShape = new 2DShape(); … myShape = new Triangle(); 14/10/2009 Hadziq Fabroyir - Informatics ITS 15
Overriding Methods A child class can override the definition of an inherited method in favor of its own That is, a child can redefine a method that it inherits from its parent The new method must have the same signature as the parent's method, but can have a different implementation. 14/10/2009 Hadziq Fabroyir - Informatics ITS 16
Lect 28	P. 17 Winter Quarter Function Overloading C++ supports writing more than one function with the same name but different argument lists.  This could include: different data types different number of arguments The advantage is that the same apparent function can be called to perform similar but different tasks.  The following will show an example of this.
Lect 28	P. 18 Winter Quarter Function Overloading void swap (int *a, int *b); void swap (float *c, float *d); void swap (char *p, char *q); int main ( )  { int a = 4, b = 6 ; float c = 16.7, d = -7.89 ; char p = 'M' , q = 'n' ; 	swap (&a, &b) ; 	swap (&c, &d); 	swap (&p, &q);  }
Lect 28	P. 19 Winter Quarter Function Overloading void swap (int *a, int *b) { int temp;  temp = *a;  *a = *b;  *b = temp; } void swap (float *c, float *d) {float temp;  temp = *c;  *c = *d;  *d = temp;} void swap (char *p, char *q) {char temp;  temp = *p;  *p = *q;  *q = temp;}
Comparison Overloading Overloadingdeals with multiple methods in the same class with the same name but different signatures Overloadinglets you define a similar operation in different ways for different data Example: int foo(string[] bar); intfoo(intbar1, floata); Overriding Overridingdeals with two methods, one in a parent class and one in a child class, that have the same signature Overridinglets you define a similar operation in different ways for different object types Example: class Base { publicvirtualintfoo() {} } class Derived { publicoverrideintfoo() {}} 14/10/2009 Hadziq Fabroyir - Informatics ITS 20
Declaring a Derived Class Define a new class  DerivedClass which extends BaseClass class BaseClass  	{ // class contents 	}   class DerivedClass : BaseClass   { // class contents 	} 14/10/2009 Hadziq Fabroyir - Informatics ITS 21
Declaring a Derived Class class A : base classaccess specifier B {		 member access specifier(s): 	... 		member data and member function(s); 	... } Valid access specifiers include public, protected, and private 14/10/2009 Hadziq Fabroyir - Informatics ITS 22
Public Inheritance class A : public B {		// Class A now inherits the members of Class B 		// with no change in the “access specifier” for }		// the inherited members 14/10/2009 Hadziq Fabroyir - Informatics ITS 23

Weitere ähnliche Inhalte

Was ist angesagt?

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++Sujan Mia
 
Inheritance
InheritanceInheritance
InheritanceTech_MX
 
Friend functions
Friend functions Friend functions
Friend functions Megha Singh
 
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
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Ameen Sha'arawi
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Paumil Patel
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 
Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)Gajendra Singh Thakur
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++Sujan Mia
 

Was ist angesagt? (20)

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Friend functions
Friend functions Friend functions
Friend functions
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Inheritance
InheritanceInheritance
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)
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 

Andere mochten auch

#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator OverloadingHadziq Fabroyir
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritanceshatha00
 
Oop inheritance
Oop inheritanceOop inheritance
Oop inheritanceZubair CH
 
C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++richards9696
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting Skillwise Group
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceAtit Patumvan
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++Nitin Jawla
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculationsandeepkrish2712
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Kumar Boro
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++Aabha Tiwari
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
Valve Selection & Sizing
Valve Selection & SizingValve Selection & Sizing
Valve Selection & SizingRanjeet Kumar
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++gourav kottawar
 

Andere mochten auch (20)

#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
Inheritance
InheritanceInheritance
Inheritance
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Oop inheritance
Oop inheritanceOop inheritance
Oop inheritance
 
Oop l2
Oop l2Oop l2
Oop l2
 
C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : Inheritance
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculation
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
Valve selections
Valve selectionsValve selections
Valve selections
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Valve Selection & Sizing
Valve Selection & SizingValve Selection & Sizing
Valve Selection & Sizing
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 

Ähnlich wie #OOP_D_ITS - 6th - C++ Oop Inheritance

chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdfstudy material
 
#OOP_D_ITS - 9th - Template
#OOP_D_ITS - 9th - Template#OOP_D_ITS - 9th - Template
#OOP_D_ITS - 9th - TemplateHadziq Fabroyir
 
Inheritance (with classifications)
Inheritance (with classifications)Inheritance (with classifications)
Inheritance (with classifications)Redwan Islam
 
Chapter 7:Understanding Class Inheritance
Chapter 7:Understanding Class InheritanceChapter 7:Understanding Class Inheritance
Chapter 7:Understanding Class InheritanceIt Academy
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritancebunnykhan
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3Naga Muruga
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming conceptsGanesh Karthik
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)SURBHI SAROHA
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class StructureHadziq Fabroyir
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingRenas Rekany
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxkristinatemen
 

Ähnlich wie #OOP_D_ITS - 6th - C++ Oop Inheritance (20)

chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
#OOP_D_ITS - 9th - Template
#OOP_D_ITS - 9th - Template#OOP_D_ITS - 9th - Template
#OOP_D_ITS - 9th - Template
 
Inheritance (with classifications)
Inheritance (with classifications)Inheritance (with classifications)
Inheritance (with classifications)
 
Chapter 7:Understanding Class Inheritance
Chapter 7:Understanding Class InheritanceChapter 7:Understanding Class Inheritance
Chapter 7:Understanding Class Inheritance
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
CS3391 -OOP -UNIT – II  NOTES FINAL.pdfCS3391 -OOP -UNIT – II  NOTES FINAL.pdf
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
 
Oops recap
Oops recapOops recap
Oops recap
 
lecture3.pptx
lecture3.pptxlecture3.pptx
lecture3.pptx
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
7 class objects
7 class objects7 class objects
7 class objects
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure
 
Object
ObjectObject
Object
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
Inheritance and Interfaces
Inheritance and InterfacesInheritance and Interfaces
Inheritance and Interfaces
 

Mehr von Hadziq Fabroyir

An Immersive Map Exploration System Using Handheld Device
An Immersive Map Exploration System Using Handheld DeviceAn Immersive Map Exploration System Using Handheld Device
An Immersive Map Exploration System Using Handheld DeviceHadziq Fabroyir
 
在不同尺度遙現系統中具空間感知特性的使用者介面開發
在不同尺度遙現系統中具空間感知特性的使用者介面開發在不同尺度遙現系統中具空間感知特性的使用者介面開發
在不同尺度遙現系統中具空間感知特性的使用者介面開發Hadziq Fabroyir
 
NTUST Course Selection (Revision: Fall 2016)
NTUST Course Selection (Revision: Fall 2016)NTUST Course Selection (Revision: Fall 2016)
NTUST Course Selection (Revision: Fall 2016)Hadziq Fabroyir
 
律法保護的五件事
律法保護的五件事律法保護的五件事
律法保護的五件事Hadziq Fabroyir
 
Pelajaran 5 第五課 • Telepon 給打電話
Pelajaran 5 第五課 • Telepon 給打電話Pelajaran 5 第五課 • Telepon 給打電話
Pelajaran 5 第五課 • Telepon 給打電話Hadziq Fabroyir
 
Pelajaran 4 第四課 • Belanja 買東西
Pelajaran 4 第四課 • Belanja 買東西Pelajaran 4 第四課 • Belanja 買東西
Pelajaran 4 第四課 • Belanja 買東西Hadziq Fabroyir
 
Pelajaran 3 第三課 • Transportasi 交通
Pelajaran 3 第三課 • Transportasi 交通Pelajaran 3 第三課 • Transportasi 交通
Pelajaran 3 第三課 • Transportasi 交通Hadziq Fabroyir
 
Pelajaran 2 第二課 • Di Restoran 在餐廳
Pelajaran 2 第二課 • Di Restoran 在餐廳Pelajaran 2 第二課 • Di Restoran 在餐廳
Pelajaran 2 第二課 • Di Restoran 在餐廳Hadziq Fabroyir
 
Pelajaran 1 第一課 • Perkenalan Diri 自我介紹
Pelajaran 1 第一課 • Perkenalan Diri 自我介紹Pelajaran 1 第一課 • Perkenalan Diri 自我介紹
Pelajaran 1 第一課 • Perkenalan Diri 自我介紹Hadziq Fabroyir
 
Living in Taiwan for Dummies
Living in Taiwan for DummiesLiving in Taiwan for Dummies
Living in Taiwan for DummiesHadziq Fabroyir
 
How to Select Course at NTUST
How to Select Course at NTUSTHow to Select Course at NTUST
How to Select Course at NTUSTHadziq Fabroyir
 
NTUST-IMSA • International Students Orientation
NTUST-IMSA • International Students OrientationNTUST-IMSA • International Students Orientation
NTUST-IMSA • International Students OrientationHadziq Fabroyir
 
NTUST Course Selection - How to
NTUST Course Selection - How toNTUST Course Selection - How to
NTUST Course Selection - How toHadziq Fabroyir
 
#OOP_D_ITS - 8th - Class Diagram
#OOP_D_ITS - 8th - Class Diagram#OOP_D_ITS - 8th - Class Diagram
#OOP_D_ITS - 8th - Class DiagramHadziq Fabroyir
 
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting StartedHadziq Fabroyir
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And ReferencesHadziq Fabroyir
 
#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++Hadziq Fabroyir
 
#OOP_D_ITS - 1st - Introduction To Object Oriented Programming
#OOP_D_ITS - 1st - Introduction To Object Oriented Programming#OOP_D_ITS - 1st - Introduction To Object Oriented Programming
#OOP_D_ITS - 1st - Introduction To Object Oriented ProgrammingHadziq Fabroyir
 

Mehr von Hadziq Fabroyir (20)

An Immersive Map Exploration System Using Handheld Device
An Immersive Map Exploration System Using Handheld DeviceAn Immersive Map Exploration System Using Handheld Device
An Immersive Map Exploration System Using Handheld Device
 
在不同尺度遙現系統中具空間感知特性的使用者介面開發
在不同尺度遙現系統中具空間感知特性的使用者介面開發在不同尺度遙現系統中具空間感知特性的使用者介面開發
在不同尺度遙現系統中具空間感知特性的使用者介面開發
 
NTUST Course Selection (Revision: Fall 2016)
NTUST Course Selection (Revision: Fall 2016)NTUST Course Selection (Revision: Fall 2016)
NTUST Course Selection (Revision: Fall 2016)
 
律法保護的五件事
律法保護的五件事律法保護的五件事
律法保護的五件事
 
Pelajaran 5 第五課 • Telepon 給打電話
Pelajaran 5 第五課 • Telepon 給打電話Pelajaran 5 第五課 • Telepon 給打電話
Pelajaran 5 第五課 • Telepon 給打電話
 
Pelajaran 4 第四課 • Belanja 買東西
Pelajaran 4 第四課 • Belanja 買東西Pelajaran 4 第四課 • Belanja 買東西
Pelajaran 4 第四課 • Belanja 買東西
 
Pelajaran 3 第三課 • Transportasi 交通
Pelajaran 3 第三課 • Transportasi 交通Pelajaran 3 第三課 • Transportasi 交通
Pelajaran 3 第三課 • Transportasi 交通
 
Pelajaran 2 第二課 • Di Restoran 在餐廳
Pelajaran 2 第二課 • Di Restoran 在餐廳Pelajaran 2 第二課 • Di Restoran 在餐廳
Pelajaran 2 第二課 • Di Restoran 在餐廳
 
Pelajaran 1 第一課 • Perkenalan Diri 自我介紹
Pelajaran 1 第一課 • Perkenalan Diri 自我介紹Pelajaran 1 第一課 • Perkenalan Diri 自我介紹
Pelajaran 1 第一課 • Perkenalan Diri 自我介紹
 
Living in Taiwan for Dummies
Living in Taiwan for DummiesLiving in Taiwan for Dummies
Living in Taiwan for Dummies
 
How to Select Course at NTUST
How to Select Course at NTUSTHow to Select Course at NTUST
How to Select Course at NTUST
 
NTUST-IMSA • International Students Orientation
NTUST-IMSA • International Students OrientationNTUST-IMSA • International Students Orientation
NTUST-IMSA • International Students Orientation
 
NTUST Course Selection - How to
NTUST Course Selection - How toNTUST Course Selection - How to
NTUST Course Selection - How to
 
Brain Battle Online
Brain Battle OnlineBrain Battle Online
Brain Battle Online
 
Manajemen Waktu
Manajemen WaktuManajemen Waktu
Manajemen Waktu
 
#OOP_D_ITS - 8th - Class Diagram
#OOP_D_ITS - 8th - Class Diagram#OOP_D_ITS - 8th - Class Diagram
#OOP_D_ITS - 8th - Class Diagram
 
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References
 
#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++
 
#OOP_D_ITS - 1st - Introduction To Object Oriented Programming
#OOP_D_ITS - 1st - Introduction To Object Oriented Programming#OOP_D_ITS - 1st - Introduction To Object Oriented Programming
#OOP_D_ITS - 1st - Introduction To Object Oriented Programming
 

Kürzlich hochgeladen

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Kürzlich hochgeladen (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

#OOP_D_ITS - 6th - C++ Oop Inheritance

  • 1. C++ OOP :: Inheritance 14/10/2009 1 Hadziq Fabroyir - Informatics ITS
  • 2. Classes Characteristic Classes are used to accomplish: Modularity► Scope for global (static) methods Blueprints for generating objects or instances Classes support Data encapsulation - private data and implementation. Inheritance-code reuse 14/10/2009 Hadziq Fabroyir - Informatics ITS 2
  • 3. Inheritance Inheritance allows a software developer to derive a new class from an existing one. 14/10/2009 Hadziq Fabroyir - Informatics ITS 3
  • 4. Inheritance The existing class is called the parent, super, or baseclass. The derived class is called a child or subclass. 14/10/2009 Hadziq Fabroyir - Informatics ITS 4
  • 5.
  • 6. The child has special rights to the parents methods and data.
  • 7. Public access like any one else
  • 8. Protected access available only to child classes (and their descendants).
  • 9. The child has its own unique behaviors and data.14/10/2009 Hadziq Fabroyir - Informatics ITS 5
  • 10. Inheritance Inheritance relationships are often shown graphically in a classdiagram with the arrow pointing to the parent class. Inheritance should create an is-arelationship, meaning the child is a more specific version of the parent. 14/10/2009 Hadziq Fabroyir - Informatics ITS 6 Animal Bird
  • 11. Examples: Base Classes and Derived Classes 14/10/2009 Hadziq Fabroyir - Informatics ITS 7
  • 12. Single / Multiple Inheritance ? Some languages, e.g., C++, allowMultiple inheritance, which allows a class to be derived from two or more classes, inheriting the members of all parents. C# and Java support only Single inheritance, meaning that a derived class can have only one parent class. 14/10/2009 Hadziq Fabroyir - Informatics ITS 8
  • 13. Class Hierarchies A child class of one parent can be the parent of another child, forming a class hierarchy 14/10/2009 Hadziq Fabroyir - Informatics ITS 9
  • 14. Classify It ! 14/10/2009 Hadziq Fabroyir - Informatics ITS 10
  • 15. Class Hierarchies 14/10/2009 Hadziq Fabroyir - Informatics ITS 11
  • 16. Classify It ! 14/10/2009 Hadziq Fabroyir - Informatics ITS 12
  • 17. Class Hierarchies 14/10/2009 Hadziq Fabroyir - Informatics ITS 13
  • 18. Class Hierarchies An inherited member is continually passed down the line Inheritance is transitive Good class design puts all common features as high in the hierarchy as is reasonable. Avoids redundant code. 14/10/2009 Hadziq Fabroyir - Informatics ITS 14
  • 19. References and Inheritance An object reference can refer to an object of its class, or to an object of any class derived from it by inheritance. For example, if the 2DShape class is used to derive a child class called Triangle, then a 2DShape reference can be used to point to a Triangle object. 2DShape myShape; myShape = new 2DShape(); … myShape = new Triangle(); 14/10/2009 Hadziq Fabroyir - Informatics ITS 15
  • 20. Overriding Methods A child class can override the definition of an inherited method in favor of its own That is, a child can redefine a method that it inherits from its parent The new method must have the same signature as the parent's method, but can have a different implementation. 14/10/2009 Hadziq Fabroyir - Informatics ITS 16
  • 21. Lect 28 P. 17 Winter Quarter Function Overloading C++ supports writing more than one function with the same name but different argument lists. This could include: different data types different number of arguments The advantage is that the same apparent function can be called to perform similar but different tasks. The following will show an example of this.
  • 22. Lect 28 P. 18 Winter Quarter Function Overloading void swap (int *a, int *b); void swap (float *c, float *d); void swap (char *p, char *q); int main ( ) { int a = 4, b = 6 ; float c = 16.7, d = -7.89 ; char p = 'M' , q = 'n' ; swap (&a, &b) ; swap (&c, &d); swap (&p, &q); }
  • 23. Lect 28 P. 19 Winter Quarter Function Overloading void swap (int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } void swap (float *c, float *d) {float temp; temp = *c; *c = *d; *d = temp;} void swap (char *p, char *q) {char temp; temp = *p; *p = *q; *q = temp;}
  • 24. Comparison Overloading Overloadingdeals with multiple methods in the same class with the same name but different signatures Overloadinglets you define a similar operation in different ways for different data Example: int foo(string[] bar); intfoo(intbar1, floata); Overriding Overridingdeals with two methods, one in a parent class and one in a child class, that have the same signature Overridinglets you define a similar operation in different ways for different object types Example: class Base { publicvirtualintfoo() {} } class Derived { publicoverrideintfoo() {}} 14/10/2009 Hadziq Fabroyir - Informatics ITS 20
  • 25. Declaring a Derived Class Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class contents } 14/10/2009 Hadziq Fabroyir - Informatics ITS 21
  • 26. Declaring a Derived Class class A : base classaccess specifier B { member access specifier(s): ... member data and member function(s); ... } Valid access specifiers include public, protected, and private 14/10/2009 Hadziq Fabroyir - Informatics ITS 22
  • 27. Public Inheritance class A : public B { // Class A now inherits the members of Class B // with no change in the “access specifier” for } // the inherited members 14/10/2009 Hadziq Fabroyir - Informatics ITS 23
  • 28. Protected Inheritance class A : protected B { // Class A now inherits the members of Class B // with public members “promoted” to protected } // but no other changes to the inherited members 14/10/2009 Hadziq Fabroyir - Informatics ITS 24
  • 29. Private Inheritance class A : private B { // Class A now inherits the members of Class B // with public and protected members } // “promoted” to private 14/10/2009 Hadziq Fabroyir - Informatics ITS 25
  • 30. For your practice … Exercise Declare Classes of ... Shape (ex: public getColor(), protected color) 2D Shape, 3D Shape (ex: public getArea(), protected edgeLength) Triangle, Circle, Square; Cube, Cylinder, Sphere Lab Session for lower order (Senin, 15.00-17.00) Lab Session for upper order (Senin, 19.00-21.00) Please provide: the softcopy(send it by email – deadline Sunday 23:59) the hardcopy(bring it when attending the lab session) 14/10/2009 Hadziq Fabroyir - Informatics ITS 26
  • 31. ☺~ Next: Virtual & Polymorphism ~☺ [ 27 ] Hadziq Fabroyir - Informatics ITS 14/10/2009

Hinweis der Redaktion

  1. The child inherits characteristics of the parent.Methods and data defined for the parent class.The child has special rights to the parents methods and data.Public access like any one elseProtected access available only to child classes (and their descendants).The child has its own unique behaviors and data.