SlideShare a Scribd company logo
1 of 49
Download to read offline
Inheritance
Kotlin Study Group #3
Andy Lu
2021.04.08
Who am I
Andy Lu
Android Engineer in FutureDial
第二屆 Kotlin 讀書會導讀者
❤ Kotlin
❤ Flutter
Medium: https://medium.com/@andyludeveloper
2
Agenda
● What’s inheritance?
● When inherited?
● How to inherit?
○ Superclass/Base class
○ Subclass/Derived class
○ Any
● Q&A 3
What’s inheritance?
4
What’s inheritance?
5
Student Class Teacher Class
What’s inheritance?
6
Student Class Teacher Class
Same
properties
Same
function
What’s inheritance?
7
Superclass/ base class
Subclass/ derived class
What’s inheritance?
8
● To avoid duplicate code.
● Override functions and
properties.
● Subclass can add own
functions or properties.
When inherit?
9
is-a relationship
10
11
● Student is a People. ✅
is-a relationship
12
● Student is a People. ✅
● Teacher is a People. ✅
is-a relationship
13
● Student is a People. ✅
● Teacher is a People. ✅
● Tiger is a People. ❌
is-a relationship
14
● Student is a People. ✅
● Teacher is a People. ✅
● Tiger is a People. ❌
● Aircraft is a People. ❌
is-a relationship
How to inherit?
15
16
Superclass/ base class
Subclass/ derived class
Inheritance tree
Superclass/Base class
17
Class
18
Can not be inherited
19
Can not be inherited
20
��
Superclass
21
Superclass
22
Add open keyword
Can be inherited
23
��
Subclass/Derived class
24
How to inherit?
25
Inherit a superclass
26
Inherit a superclass
27
: superclass name (constructor)
Advantage
28
1. Can access all open functions and properties
from superclass.
2. Can override all open functions or properties.
3. Can create own functions or properties.
Access
29
Access
30
Access
31
Hello, my name is Andy
Not allow to access
32
private keyword make function non-accessible
Not allow to access
33
Override
34
Override
35
Override
36
1. Add open keyword
Override
37
1. Add open keyword
2. Use override keyword
Override
38
Student Andy say hi
Create
39
Create
40
Create
41
Andy is doing home work
Create
42
Thinking
43
❓
Thinking
44
Any Class
45
Any class
46
Any class
47
● equals()
● hashCode()
● toString()
Q & A
48
49
Next Chapter:
abstract classes and interfaces: Serious Polymorphism

More Related Content

What's hot (20)

Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
 
Turing machine by_deep
Turing machine by_deepTuring machine by_deep
Turing machine by_deep
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Digital image processing
Digital image processingDigital image processing
Digital image processing
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java rmi
Java rmiJava rmi
Java rmi
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Object detection
Object detectionObject detection
Object detection
 
Java History
Java HistoryJava History
Java History
 
Basics of IPTV
Basics of IPTVBasics of IPTV
Basics of IPTV
 
History of java'
History of java'History of java'
History of java'
 
Digital Image Processing 3rd edition Rafael C. Gonzalez, Richard E. Woods.pdf
Digital Image Processing 3rd edition Rafael C. Gonzalez, Richard E. Woods.pdfDigital Image Processing 3rd edition Rafael C. Gonzalez, Richard E. Woods.pdf
Digital Image Processing 3rd edition Rafael C. Gonzalez, Richard E. Woods.pdf
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
QSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and JitQSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and Jit
 

Similar to [2021] kotlin - inheritance

GDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdfGDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdfgdscmikroskil
 
Teaching opensource 2015
Teaching opensource 2015Teaching opensource 2015
Teaching opensource 2015Craig Gardner
 
Informal talk at pict
Informal talk at pictInformal talk at pict
Informal talk at pictMayank Jain
 
Blended Learn - Today and Tomorrow - Disruptive
Blended Learn - Today and Tomorrow - DisruptiveBlended Learn - Today and Tomorrow - Disruptive
Blended Learn - Today and Tomorrow - DisruptiveDreamBox Learning
 
Blended Learning: Today and Tomorrow
Blended Learning: Today and TomorrowBlended Learning: Today and Tomorrow
Blended Learning: Today and TomorrowDreamBox Learning
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questionsKeet Sugathadasa
 
EDT 6200 There's an App for That
EDT 6200 There's an App for ThatEDT 6200 There's an App for That
EDT 6200 There's an App for ThatEnochWilliams1
 
Road From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey Parnell
Road From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey ParnellRoad From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey Parnell
Road From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey ParnellRyerson Student Affairs
 
January 14 CET Committee Preso notes
January 14 CET Committee Preso notesJanuary 14 CET Committee Preso notes
January 14 CET Committee Preso notesCharles F. Patton MS
 
OSCC14: Using OpenSimulator in K-12 Schools
OSCC14: Using OpenSimulator in K-12 SchoolsOSCC14: Using OpenSimulator in K-12 Schools
OSCC14: Using OpenSimulator in K-12 SchoolsDavid W. Deeds
 
Flipping the classroom with i tunes u actem.pdf
Flipping the classroom with i tunes u   actem.pdfFlipping the classroom with i tunes u   actem.pdf
Flipping the classroom with i tunes u actem.pdfSharon Chasse
 
LIBST110A - Summer 2013 - Section 2136 - Session 1
LIBST110A - Summer 2013 - Section 2136 - Session 1LIBST110A - Summer 2013 - Section 2136 - Session 1
LIBST110A - Summer 2013 - Section 2136 - Session 1mkinneyccclib
 
Teaching open source 2016
Teaching open source 2016Teaching open source 2016
Teaching open source 2016Craig Gardner
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programmingsharmisivarajah
 
Educational Google Apps.docx
Educational Google Apps.docxEducational Google Apps.docx
Educational Google Apps.docxStacyLevering
 
Educational Google Apps.docx
Educational Google Apps.docxEducational Google Apps.docx
Educational Google Apps.docxStacyLevering
 
Meet the Flat Classroom 2012
Meet the Flat Classroom 2012Meet the Flat Classroom 2012
Meet the Flat Classroom 2012Flat Classrooms
 

Similar to [2021] kotlin - inheritance (20)

GDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdfGDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdf
 
TIE CO Flat Classroom 2013
TIE CO Flat Classroom 2013TIE CO Flat Classroom 2013
TIE CO Flat Classroom 2013
 
Teaching opensource 2015
Teaching opensource 2015Teaching opensource 2015
Teaching opensource 2015
 
Informal talk at pict
Informal talk at pictInformal talk at pict
Informal talk at pict
 
Blended Learn - Today and Tomorrow - Disruptive
Blended Learn - Today and Tomorrow - DisruptiveBlended Learn - Today and Tomorrow - Disruptive
Blended Learn - Today and Tomorrow - Disruptive
 
Blended Learning: Today and Tomorrow
Blended Learning: Today and TomorrowBlended Learning: Today and Tomorrow
Blended Learning: Today and Tomorrow
 
Ai powered education
Ai powered  educationAi powered  education
Ai powered education
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questions
 
EDT 6200 There's an App for That
EDT 6200 There's an App for ThatEDT 6200 There's an App for That
EDT 6200 There's an App for That
 
Road From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey Parnell
Road From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey ParnellRoad From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey Parnell
Road From Ryerson - Rachel Barreca, Andrew Bisnauth, Bailey Parnell
 
January 14 CET Committee Preso notes
January 14 CET Committee Preso notesJanuary 14 CET Committee Preso notes
January 14 CET Committee Preso notes
 
Extreme Makeover 3 6 08
Extreme  Makeover 3 6 08Extreme  Makeover 3 6 08
Extreme Makeover 3 6 08
 
OSCC14: Using OpenSimulator in K-12 Schools
OSCC14: Using OpenSimulator in K-12 SchoolsOSCC14: Using OpenSimulator in K-12 Schools
OSCC14: Using OpenSimulator in K-12 Schools
 
Flipping the classroom with i tunes u actem.pdf
Flipping the classroom with i tunes u   actem.pdfFlipping the classroom with i tunes u   actem.pdf
Flipping the classroom with i tunes u actem.pdf
 
LIBST110A - Summer 2013 - Section 2136 - Session 1
LIBST110A - Summer 2013 - Section 2136 - Session 1LIBST110A - Summer 2013 - Section 2136 - Session 1
LIBST110A - Summer 2013 - Section 2136 - Session 1
 
Teaching open source 2016
Teaching open source 2016Teaching open source 2016
Teaching open source 2016
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Educational Google Apps.docx
Educational Google Apps.docxEducational Google Apps.docx
Educational Google Apps.docx
 
Educational Google Apps.docx
Educational Google Apps.docxEducational Google Apps.docx
Educational Google Apps.docx
 
Meet the Flat Classroom 2012
Meet the Flat Classroom 2012Meet the Flat Classroom 2012
Meet the Flat Classroom 2012
 

Recently uploaded

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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

[2021] kotlin - inheritance