SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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++
 

Destaque

#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
 

Destaque (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++
 

Semelhante a #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
 

Semelhante a #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
 

Mais de 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
 

Mais de 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
 

Último

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

#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

Notas do Editor

  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.