SlideShare a Scribd company logo
Object Oriented
Programming
Andi Nurkholis, S.Kom., M.Kom.
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2019-2020
April 16, 2020
7.1 Inheritance
2
Inheritance in Java
Inheritance is an important pillar of OOP
(Object Oriented Programming). It is the
mechanism in java by which one class is
allow to inherit the features (fields and
methods) of another class.
3
4
Important Terminology
• Super Class: The class whose features are inherited is known as super
class(or a base class or a parent class).
• Sub Class: The class that inherits the other class is known as sub
class(or a derived class, extended class, or child class). The subclass
can add its own fields and methods in addition to the superclass fields
and methods.
5
Important Terminology (cont.)
• Reusability: Inheritance supports the concept of “reusability”, i.e. when
we want to create a new class and there is already a class that
includes some of the code that we want, we can derive our new class
from the existing class. By doing this, we are reusing the fields and
methods of the existing class.
How to Use Inheritance in Java?
The keyword used for inheritance is extends. Syntax:
6
class derived-class extends base-class
{
//methods and fields
}
Inheritance Illustration
7
Illustration Explanation
In previous illustration, when an object of MountainBike class is
created, a copy of the all methods and fields of the superclass acquire
memory in this object. That is why, by using the object of the subclass
we can also access the members of a superclass.
Please note that during inheritance only object of subclass is created,
not the superclass. For more, refer Java Object Creation of Inherited
Class.
8
9
Types of Inheritance
There are Various types of inheritance:
• Single Inheritance
• Multiple Inheritance
• Multilevel Inheritance
• Hierarchical Inheritance
• Hybrid Inheritance
Note: Java doesn't support hybrid/Multiple inheritance
Single Inheritance
In Single Inheritance one class extends another class (one class only).
10
In above diagram, Class B extends only Class A. Class A is a super class
and Class B is a Sub-class.
Multiple Inheritance
In Multiple Inheritance, one class extending more than one class. Java
does not support multiple inheritance.
11
As per above diagram, Class C extends Class A and Class B both.
Multilevel Inheritance
In Multilevel Inheritance, one class can inherit from
a derived class. Hence, the derived class becomes
the base class for the new class.
As per shown in diagram Class C is subclass of B
and B is a of subclass Class A.
12
13
Hierarchical Inheritance
In Hierarchical Inheritance, one class is inherited by many sub classes.
As per above example, Class B, C, and D inherit the same class A.
Hybrid Inheritance
Hybrid inheritance is a combination of Single and Multiple inheritance.
Java doesn't support hybrid inheritance
14
As per above example, all the public and protected members of Class A are
inherited into Class D, first via Class B and secondly via Class C.
Important Facts of Inheritance in Java
• Default superclass: Except Object class, which has no superclass, every
class has one and only one direct superclass (single inheritance). In the
absence of any other explicit superclass, every class is implicitly a
subclass of Object class.
• Superclass can only be one: A superclass can have any number of
subclasses. But a subclass can have only one superclass. This is
because Java does not support multiple inheritance with classes.
Although with interfaces, multiple inheritance is supported by java.
15
Important Facts of Inheritance in Java (cont.)
• Inheriting Constructors: A subclass inherits all the members (fields,
methods, and nested classes) from its superclass. Constructors are not
members, so they are not inherited by subclasses, but the constructor
of the superclass can be invoked from the subclass.
• Private member inheritance: A subclass does not inherit the private
members of its parent class. However, if the superclass has public or
protected methods(like getters and setters) for accessing its private
fields, these can also be used by the subclass.
16
So, Why and When to Use "Inheritance"?
The most important use is the reusability of code. The code that is
present in the parent class doesn’t need to be written again in the child
class.
What is the meaning? With inheritance, we can reuse attributes and
methods of an existing class when you create a new class.
17
Thank You, Next …
Polymorphism
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2019-2020
Andi Nurkholis, S.Kom., M.Kom.
April 16, 2020

More Related Content

PPTX
Inheritance
PPS
Dacj 2-1 a
PDF
Chapter25 inheritance-i
PPTX
Object oriented concepts with java
PPT
Inner Classes
PPTX
Programming presentation
PPTX
Introduction to Java Part-3
PPTX
C# Access modifiers
Inheritance
Dacj 2-1 a
Chapter25 inheritance-i
Object oriented concepts with java
Inner Classes
Programming presentation
Introduction to Java Part-3
C# Access modifiers

Similar to Object Oriented Programming - 7.1. Inheritance (20)

PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
PPTX
inheritance.pptxfdfgfgfgfgdfgfgdfgdfgerre
PPTX
Inheritance in OOPs with java
PPTX
Inheritance in Java is a mechanism in which one object acquires all the prope...
PDF
java_vyshali.pdf
PPTX
Ayan Das_25300121057.pptx
PPTX
Inheritance in oop
PDF
‏‏‏‏‏‏oop lecture objectives will come.pdf
PDF
IRJET- Inheritance in Java
PPTX
Inheritance in java
PPTX
Java(inheritance)
PPTX
Java Inheritance
PPTX
Interesting Concept of Object Oriented Programming
PPTX
Inheritance in Java - An Introduction & types
PPTX
Inheritance & interface ppt Inheritance
PPTX
Inheritance and Interfaces
PPTX
Inheritance-in-Java.pptxxxxxxxxxxxxxxxxx
PDF
Inheritance in Java.pdf
PPTX
Inheritance
PPTX
INHERITANCE.pptx
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
inheritance.pptxfdfgfgfgfgdfgfgdfgdfgerre
Inheritance in OOPs with java
Inheritance in Java is a mechanism in which one object acquires all the prope...
java_vyshali.pdf
Ayan Das_25300121057.pptx
Inheritance in oop
‏‏‏‏‏‏oop lecture objectives will come.pdf
IRJET- Inheritance in Java
Inheritance in java
Java(inheritance)
Java Inheritance
Interesting Concept of Object Oriented Programming
Inheritance in Java - An Introduction & types
Inheritance & interface ppt Inheritance
Inheritance and Interfaces
Inheritance-in-Java.pptxxxxxxxxxxxxxxxxx
Inheritance in Java.pdf
Inheritance
INHERITANCE.pptx
Ad

More from AndiNurkholis1 (20)

PDF
Technopreneurship - 9 Analisis Biaya dan Keuangan
PDF
Pengantar Bisnis - 14 Manajemen Keuangan
PDF
Pengantar Bisnis - 13 Manajemen Operasi
PDF
Pengantar Bisnis - 12 Kebijakan Harga
PDF
Pengantar Bisnis - 11 Kebijakan Distribusi
PDF
Technopreneurship - 8 Manajemen Sumber Daya Manusia
PDF
Pengantar Bisnis - 10 Kebijakan Produk
PDF
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
PDF
Pengantar Bisnis - 9 Manajemen Pemasaran
PDF
Technopreneurship - 6 Business Plan
PDF
Pengantar Bisnis - 8 Kepemimpinan
PDF
Technopreneurship - 5 Model Bisnis
PDF
Technopreneurship - 4 Studi Kelayakan Usaha
PDF
Pengantar Bisnis - 7 Motivasi Kerja
PDF
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
PDF
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
PDF
Technopreneurship - 3 Ide dan Prinsip Bisnis
PDF
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
PDF
Technopreneurship - 2 Pengantar Technopreneurship
PDF
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
Technopreneurship - 9 Analisis Biaya dan Keuangan
Pengantar Bisnis - 14 Manajemen Keuangan
Pengantar Bisnis - 13 Manajemen Operasi
Pengantar Bisnis - 12 Kebijakan Harga
Pengantar Bisnis - 11 Kebijakan Distribusi
Technopreneurship - 8 Manajemen Sumber Daya Manusia
Pengantar Bisnis - 10 Kebijakan Produk
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
Pengantar Bisnis - 9 Manajemen Pemasaran
Technopreneurship - 6 Business Plan
Pengantar Bisnis - 8 Kepemimpinan
Technopreneurship - 5 Model Bisnis
Technopreneurship - 4 Studi Kelayakan Usaha
Pengantar Bisnis - 7 Motivasi Kerja
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
Technopreneurship - 3 Ide dan Prinsip Bisnis
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
Technopreneurship - 2 Pengantar Technopreneurship
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...
madgavkar20181017ppt McKinsey Presentation.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
The AUB Centre for AI in Media Proposal.docx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
“AI and Expert System Decision Support & Business Intelligence Systems”
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
GamePlan Trading System Review: Professional Trader's Honest Take
The Rise and Fall of 3GPP – Time for a Sabbatical?
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Monthly Chronicles - July 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Object Oriented Programming - 7.1. Inheritance

  • 1. Object Oriented Programming Andi Nurkholis, S.Kom., M.Kom. Study Program of Informatics Faculty of Engineering and Computer Science SY. 2019-2020 April 16, 2020
  • 3. Inheritance in Java Inheritance is an important pillar of OOP (Object Oriented Programming). It is the mechanism in java by which one class is allow to inherit the features (fields and methods) of another class. 3
  • 4. 4 Important Terminology • Super Class: The class whose features are inherited is known as super class(or a base class or a parent class). • Sub Class: The class that inherits the other class is known as sub class(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.
  • 5. 5 Important Terminology (cont.) • Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class.
  • 6. How to Use Inheritance in Java? The keyword used for inheritance is extends. Syntax: 6 class derived-class extends base-class { //methods and fields }
  • 8. Illustration Explanation In previous illustration, when an object of MountainBike class is created, a copy of the all methods and fields of the superclass acquire memory in this object. That is why, by using the object of the subclass we can also access the members of a superclass. Please note that during inheritance only object of subclass is created, not the superclass. For more, refer Java Object Creation of Inherited Class. 8
  • 9. 9 Types of Inheritance There are Various types of inheritance: • Single Inheritance • Multiple Inheritance • Multilevel Inheritance • Hierarchical Inheritance • Hybrid Inheritance Note: Java doesn't support hybrid/Multiple inheritance
  • 10. Single Inheritance In Single Inheritance one class extends another class (one class only). 10 In above diagram, Class B extends only Class A. Class A is a super class and Class B is a Sub-class.
  • 11. Multiple Inheritance In Multiple Inheritance, one class extending more than one class. Java does not support multiple inheritance. 11 As per above diagram, Class C extends Class A and Class B both.
  • 12. Multilevel Inheritance In Multilevel Inheritance, one class can inherit from a derived class. Hence, the derived class becomes the base class for the new class. As per shown in diagram Class C is subclass of B and B is a of subclass Class A. 12
  • 13. 13 Hierarchical Inheritance In Hierarchical Inheritance, one class is inherited by many sub classes. As per above example, Class B, C, and D inherit the same class A.
  • 14. Hybrid Inheritance Hybrid inheritance is a combination of Single and Multiple inheritance. Java doesn't support hybrid inheritance 14 As per above example, all the public and protected members of Class A are inherited into Class D, first via Class B and secondly via Class C.
  • 15. Important Facts of Inheritance in Java • Default superclass: Except Object class, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object class. • Superclass can only be one: A superclass can have any number of subclasses. But a subclass can have only one superclass. This is because Java does not support multiple inheritance with classes. Although with interfaces, multiple inheritance is supported by java. 15
  • 16. Important Facts of Inheritance in Java (cont.) • Inheriting Constructors: A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass. • Private member inheritance: A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods(like getters and setters) for accessing its private fields, these can also be used by the subclass. 16
  • 17. So, Why and When to Use "Inheritance"? The most important use is the reusability of code. The code that is present in the parent class doesn’t need to be written again in the child class. What is the meaning? With inheritance, we can reuse attributes and methods of an existing class when you create a new class. 17
  • 18. Thank You, Next … Polymorphism Study Program of Informatics Faculty of Engineering and Computer Science SY. 2019-2020 Andi Nurkholis, S.Kom., M.Kom. April 16, 2020