SlideShare a Scribd company logo
JAVA-INHERITANCE
Elizabeth Alexander
Hindustan University
INHERITANCE
● A parent-child relationship between classes
● Allows sharing of the behavior of the parent class into its child classes
■ one of the major benefits of object-oriented programming (OOP) is this code
sharing between classes through inheritance
● Child class can add new behavior or override existing behavior from parent
● Inheritance in java is a mechanism in which one object acquires all the properties
and behaviors of parent object.
● The idea behind inheritance in java is that you can create new classes that are built
upon existing classes. When you inherit from an existing class, you can reuse
methods and fields of parent class, and you can add new methods and fields also.
INHERITANCE Cont...
Why use inheritance in java?
● For Method Overriding (so runtime polymorphism can be achieved).
● For Code Reusability.
Inheritance in Java
SYNTAX OF JAVA INHERITANCE
class Super {
.....
.....
}
class Sub extends Super {
.....
.....
}
● The extends keyword indicates that a new class is derived from an existing
class. The meaning of "extends" is to increase the functionality.
INHERITANCE TERMS
● superclass, base class, parent class: terms to describe the parent in the
relationship, which shares its functionality
● subclass, derived class, child class: terms to describe the child in the
relationship, which accepts functionality from its parent
● extend, inherit, derive: become a subclass of another class
THE Super KEYWORD
● The super keyword is similar to this keyword. Following are the scenarios where
the super keyword is used.
■ It is used to differentiate the members of superclass from the
members of subclass, if they have same names.
■ It is used to invoke the superclass constructor from subclass.
● Differentiating the Members
● If a class is inheriting the properties of another class. And if the members of the
superclass have the names same as the sub class, to differentiate these variables
we use super keyword as shown below.
super.variable
super.method();
INVOKING SUPERCLASS CONSTRUCTOR
● If a class is inheriting the properties of another class, the subclass automatically
acquires the default constructor of the superclass. But if you want to call a
parameterized constructor of the superclass, you need to use the super keyword
as shown below.
super(values);
JAVA INHERITANCE EXAMPLE
TYPES OF INHERITANCE
● Three types of inheritance in java: single, multilevel and hierarchical.
● In java programming, multiple and hybrid inheritance is supported through
interface only.
TYPES OF INHERITANCE Cont...
Inheritance in Java

More Related Content

What's hot (20)

PPTX
Java Inheritance | Java Course
RAKESH P
 
PPTX
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
PDF
itft-Inheritance in java
Atul Sehdev
 
PPTX
Java inheritance
BHUVIJAYAVELU
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPT
Java inheritance
Arati Gadgil
 
PPTX
Inheritance In Java
Darpan Chelani
 
PPTX
Multiple inheritance possible in Java
Kurapati Vishwak
 
PDF
java-06inheritance
Arjun Shanka
 
PPTX
Inheritance in java
HarshitaAshwani
 
PPTX
Inheritance ppt
Nivegeetha
 
PPT
Unit 3 Java
arnold 7490
 
PPT
Java Programming - Inheritance
Oum Saokosal
 
PPT
Inheritance polymorphism-in-java
Deepak Singh
 
PPTX
Java(inheritance)
Pooja Bhojwani
 
PDF
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
PPTX
Inheritance and its types In Java
MD SALEEM QAISAR
 
PPT
Inheritance and Polymorphism
BG Java EE Course
 
PPSX
Seminar on java
shathika
 
Java Inheritance | Java Course
RAKESH P
 
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
itft-Inheritance in java
Atul Sehdev
 
Java inheritance
BHUVIJAYAVELU
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Java inheritance
Arati Gadgil
 
Inheritance In Java
Darpan Chelani
 
Multiple inheritance possible in Java
Kurapati Vishwak
 
java-06inheritance
Arjun Shanka
 
Inheritance in java
HarshitaAshwani
 
Inheritance ppt
Nivegeetha
 
Unit 3 Java
arnold 7490
 
Java Programming - Inheritance
Oum Saokosal
 
Inheritance polymorphism-in-java
Deepak Singh
 
Java(inheritance)
Pooja Bhojwani
 
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Inheritance and its types In Java
MD SALEEM QAISAR
 
Inheritance and Polymorphism
BG Java EE Course
 
Seminar on java
shathika
 

Similar to Inheritance in Java (20)

PPTX
Inheritance in oop
MuskanNazeer
 
PDF
JAVA UNIT 2 BCA students' notes IPU university
n32310997
 
PPTX
Inheritance in Java is a mechanism in which one object acquires all the prope...
Kavitha S
 
PPTX
Inheritance and Polymorphism
KartikKapgate
 
PPTX
Inheritance
PhD Research Scholar
 
PDF
4th_class.pdf
RumiHossain5
 
PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
PPTX
Chapter 9 java
Ahmad sohail Kakar
 
PPT
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
 
PDF
Introduction to Inheritance in Java for presentation
BhanuPrakashChirra
 
PPTX
Ayan Das_25300121057.pptx
Ayan974999
 
PDF
Inheritance in Java.pdf
kumari36
 
PPTX
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
PPTX
Inheritance in OOPs with java
AAKANKSHA JAIN
 
PPTX
inheritance in Java with sample program.pptx
V.V.Vanniaperumal College for Women
 
PDF
‏‏‏‏‏‏oop lecture objectives will come.pdf
nabeehmohammedtaher
 
PPTX
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
PPTX
Chapter 3i
siragezeynu
 
PPTX
Lecture 12
talha ijaz
 
Inheritance in oop
MuskanNazeer
 
JAVA UNIT 2 BCA students' notes IPU university
n32310997
 
Inheritance in Java is a mechanism in which one object acquires all the prope...
Kavitha S
 
Inheritance and Polymorphism
KartikKapgate
 
4th_class.pdf
RumiHossain5
 
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
Chapter 9 java
Ahmad sohail Kakar
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
 
Introduction to Inheritance in Java for presentation
BhanuPrakashChirra
 
Ayan Das_25300121057.pptx
Ayan974999
 
Inheritance in Java.pdf
kumari36
 
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Inheritance in OOPs with java
AAKANKSHA JAIN
 
inheritance in Java with sample program.pptx
V.V.Vanniaperumal College for Women
 
‏‏‏‏‏‏oop lecture objectives will come.pdf
nabeehmohammedtaher
 
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
Chapter 3i
siragezeynu
 
Lecture 12
talha ijaz
 
Ad

More from Elizabeth alexander (11)

PPTX
Java awt (abstract window toolkit)
Elizabeth alexander
 
PPTX
Java applet
Elizabeth alexander
 
PPTX
Io streams
Elizabeth alexander
 
PPTX
Multithreading programming in java
Elizabeth alexander
 
PPTX
Exception handling in java
Elizabeth alexander
 
PPTX
Packages in java
Elizabeth alexander
 
PPTX
Java interfaces
Elizabeth alexander
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPTX
Object oriented programming in java
Elizabeth alexander
 
PPTX
Quantitative Aptitude- Number System
Elizabeth alexander
 
PPTX
Java Programming
Elizabeth alexander
 
Java awt (abstract window toolkit)
Elizabeth alexander
 
Java applet
Elizabeth alexander
 
Multithreading programming in java
Elizabeth alexander
 
Exception handling in java
Elizabeth alexander
 
Packages in java
Elizabeth alexander
 
Java interfaces
Elizabeth alexander
 
Polymorphism in java
Elizabeth alexander
 
Object oriented programming in java
Elizabeth alexander
 
Quantitative Aptitude- Number System
Elizabeth alexander
 
Java Programming
Elizabeth alexander
 
Ad

Recently uploaded (20)

PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
community health nursing question paper 2.pdf
Prince kumar
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 

Inheritance in Java

  • 2. INHERITANCE ● A parent-child relationship between classes ● Allows sharing of the behavior of the parent class into its child classes ■ one of the major benefits of object-oriented programming (OOP) is this code sharing between classes through inheritance ● Child class can add new behavior or override existing behavior from parent ● Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. ● The idea behind inheritance in java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add new methods and fields also.
  • 3. INHERITANCE Cont... Why use inheritance in java? ● For Method Overriding (so runtime polymorphism can be achieved). ● For Code Reusability.
  • 5. SYNTAX OF JAVA INHERITANCE class Super { ..... ..... } class Sub extends Super { ..... ..... } ● The extends keyword indicates that a new class is derived from an existing class. The meaning of "extends" is to increase the functionality.
  • 6. INHERITANCE TERMS ● superclass, base class, parent class: terms to describe the parent in the relationship, which shares its functionality ● subclass, derived class, child class: terms to describe the child in the relationship, which accepts functionality from its parent ● extend, inherit, derive: become a subclass of another class
  • 7. THE Super KEYWORD ● The super keyword is similar to this keyword. Following are the scenarios where the super keyword is used. ■ It is used to differentiate the members of superclass from the members of subclass, if they have same names. ■ It is used to invoke the superclass constructor from subclass. ● Differentiating the Members ● If a class is inheriting the properties of another class. And if the members of the superclass have the names same as the sub class, to differentiate these variables we use super keyword as shown below. super.variable super.method();
  • 8. INVOKING SUPERCLASS CONSTRUCTOR ● If a class is inheriting the properties of another class, the subclass automatically acquires the default constructor of the superclass. But if you want to call a parameterized constructor of the superclass, you need to use the super keyword as shown below. super(values);
  • 10. TYPES OF INHERITANCE ● Three types of inheritance in java: single, multilevel and hierarchical. ● In java programming, multiple and hybrid inheritance is supported through interface only.