SlideShare a Scribd company logo
2
Most read
7
Most read
11
Most read
Inheritance in java
 Inheritance is a mechanism in which one class
acquires the property of another class. For
example, a child inherits the traits of his/her
parents. With inheritance, we can reuse the
fields and methods of the existing class.
Hence, inheritance facilitates Reusability and
is an important concept of OOPs.
 Single Inheritance
 Multiple Inheritance
 Multilevel Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance
In Single Inheritance one
class extends another
class (one class only).
In Multiple Inheritance, one
class extending more than
one class. Java does not
support multiple inheritance.
In Multilevel Inheritance, one class
can inherit from a derived class.
Hence, the derived class becomes
the base class for the new class.
In Hierarchical Inheritance, one
class is inherited by many sub
classes. example, Class B, C,
and D inherit the same class A.
 Hybrid inheritance is a combination of Single and Multiple
inheritance. All the public and protected members of Class A are
inherited into Class D, first via Class B and secondly via Class C.
 JAVA INHERITANCE is a mechanism in which one
class acquires the property of another class. In
Java, when an "Is-A" relationship exists between
two classes, we use Inheritance. The parent class
is called a super class and the inherited class is
called a subclass. The keyword extends is used
by the sub class to inherit the features of super
class.
 Java doesn't support hybrid/Multiple inheritance.
 Inheritance is important since it leads to the
reusability of code.
 class Doctor
{
void Doctor_Details()
{
System.out.println("Doctor Details...");
}
}
class Surgeon extends Doctor // class Surgeon is a child class of class Doctor
{
void Surgeon_Details()
{
System.out.println("Surgen Detail...");
}
}
public class Hospital
{
Public static void main(String args[])
{
Surgeon s = new Surgeon();
s.Doctor_Details();
s.Surgeon_Details();
}
}
As we know, Surgeon IS A Doctor
 The super keyword is similar to "this"
keyword. (Keyword THIS is a reference
variable in Java that refers to the current
object.)
 The keyword super can be used to access any
data member or methods of the parent class.
 Super keyword can be used at variable,
method and constructor level.
 Syntax:
super.<method-name>();
 Reusability - facility to use public methods of
base class without rewriting the same.
 Extensibility - extending the base class logic as
per business logic of the derived class.
 Data hiding - base class can decide to keep some
data private so that it cannot be altered by the
derived class
 Overriding -With inheritance, we will be able to
override the methods of the base class so that
meaningful implementation of the base class
method can be designed in the derived class.
 If a method is deleted in the "base class" or
aggregate, then we will have to re-factor in case
of using that method.Here things can get a bit
complicated in case of inheritance because our
programs will still compile, but the methods of
the subclass will no longer be overriding base
class methods. These methods will become
independent methods in their own right.
 Main disadvantage of using inheritance is that
the two classes (base and inherited class) get
tightly coupled. This means one cannot be used
independent of each other.
Thankyou
By:
Harshita Ashwani

More Related Content

PPTX
Presentation on Core java
PPTX
Interface in java
PPTX
Object Oriented Programming Using C++
PPT
Introduction to method overloading &amp; method overriding in java hdm
PPTX
Oops concept in c++ unit 3 -topic 4
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PDF
Java Presentation For Syntax
PPTX
Abstract Class Presentation
Presentation on Core java
Interface in java
Object Oriented Programming Using C++
Introduction to method overloading &amp; method overriding in java hdm
Oops concept in c++ unit 3 -topic 4
Basic Concepts of OOPs (Object Oriented Programming in Java)
Java Presentation For Syntax
Abstract Class Presentation

What's hot (20)

PPTX
Member Function in C++
PPTX
Inheritance in JAVA PPT
PPTX
Inheritance in java
PPTX
Interface in java ,multiple inheritance in java, interface implementation
PPTX
INHERITANCE IN JAVA.pptx
PDF
Arrays in Java
PPTX
OOPS In JAVA.pptx
PPTX
POP vs OOP Introduction
PPTX
Strings in Java
PPTX
Classes and objects
PPTX
Control statements in java
PPTX
Interfaces in java
PPTX
Type casting in java
PPT
User Defined Functions
PPT
Java packages
PPT
Java Programming for Designers
PPT
Inheritance in java
PPTX
Inheritance in java
PDF
PPT
Method overriding
Member Function in C++
Inheritance in JAVA PPT
Inheritance in java
Interface in java ,multiple inheritance in java, interface implementation
INHERITANCE IN JAVA.pptx
Arrays in Java
OOPS In JAVA.pptx
POP vs OOP Introduction
Strings in Java
Classes and objects
Control statements in java
Interfaces in java
Type casting in java
User Defined Functions
Java packages
Java Programming for Designers
Inheritance in java
Inheritance in java
Method overriding
Ad

Similar to Inheritance in java (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...
PPTX
Inheritance in oop
PDF
java_vyshali.pdf
PDF
‏‏‏‏‏‏oop lecture objectives will come.pdf
PPTX
PPTX
Inheritance & interface ppt Inheritance
PPTX
Java - Inheritance_multiple_inheritance.pptx
PPTX
Java Inheritance
PDF
Object Oriented Programming - 7.1. Inheritance
PPTX
Ayan Das_25300121057.pptx
PPTX
Inheritance in java
PPTX
Inheritance in Java - An Introduction & types
PPTX
Inheritance
PPTX
Inheritance
PDF
IRJET- Inheritance in Java
PPTX
Inheritance ppt
PDF
Inheritance_abstractclass_interface.pdf
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...
Inheritance in oop
java_vyshali.pdf
‏‏‏‏‏‏oop lecture objectives will come.pdf
Inheritance & interface ppt Inheritance
Java - Inheritance_multiple_inheritance.pptx
Java Inheritance
Object Oriented Programming - 7.1. Inheritance
Ayan Das_25300121057.pptx
Inheritance in java
Inheritance in Java - An Introduction & types
Inheritance
Inheritance
IRJET- Inheritance in Java
Inheritance ppt
Inheritance_abstractclass_interface.pdf
Ad

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
PPT on Performance Review to get promotions
PDF
Digital Logic Computer Design lecture notes
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
additive manufacturing of ss316l using mig welding
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CH1 Production IntroductoryConcepts.pptx
PPT on Performance Review to get promotions
Digital Logic Computer Design lecture notes
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
additive manufacturing of ss316l using mig welding
OOP with Java - Java Introduction (Basics)
Operating System & Kernel Study Guide-1 - converted.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Automation-in-Manufacturing-Chapter-Introduction.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
R24 SURVEYING LAB MANUAL for civil enggi

Inheritance in java

  • 2.  Inheritance is a mechanism in which one class acquires the property of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class. Hence, inheritance facilitates Reusability and is an important concept of OOPs.
  • 3.  Single Inheritance  Multiple Inheritance  Multilevel Inheritance  Hierarchical Inheritance  Hybrid Inheritance
  • 4. In Single Inheritance one class extends another class (one class only). In Multiple Inheritance, one class extending more than one class. Java does not support multiple inheritance.
  • 5. In Multilevel Inheritance, one class can inherit from a derived class. Hence, the derived class becomes the base class for the new class. In Hierarchical Inheritance, one class is inherited by many sub classes. example, Class B, C, and D inherit the same class A.
  • 6.  Hybrid inheritance is a combination of Single and Multiple inheritance. All the public and protected members of Class A are inherited into Class D, first via Class B and secondly via Class C.
  • 7.  JAVA INHERITANCE is a mechanism in which one class acquires the property of another class. In Java, when an "Is-A" relationship exists between two classes, we use Inheritance. The parent class is called a super class and the inherited class is called a subclass. The keyword extends is used by the sub class to inherit the features of super class.  Java doesn't support hybrid/Multiple inheritance.  Inheritance is important since it leads to the reusability of code.
  • 8.  class Doctor { void Doctor_Details() { System.out.println("Doctor Details..."); } } class Surgeon extends Doctor // class Surgeon is a child class of class Doctor { void Surgeon_Details() { System.out.println("Surgen Detail..."); } } public class Hospital { Public static void main(String args[]) { Surgeon s = new Surgeon(); s.Doctor_Details(); s.Surgeon_Details(); } } As we know, Surgeon IS A Doctor
  • 9.  The super keyword is similar to "this" keyword. (Keyword THIS is a reference variable in Java that refers to the current object.)  The keyword super can be used to access any data member or methods of the parent class.  Super keyword can be used at variable, method and constructor level.  Syntax: super.<method-name>();
  • 10.  Reusability - facility to use public methods of base class without rewriting the same.  Extensibility - extending the base class logic as per business logic of the derived class.  Data hiding - base class can decide to keep some data private so that it cannot be altered by the derived class  Overriding -With inheritance, we will be able to override the methods of the base class so that meaningful implementation of the base class method can be designed in the derived class.
  • 11.  If a method is deleted in the "base class" or aggregate, then we will have to re-factor in case of using that method.Here things can get a bit complicated in case of inheritance because our programs will still compile, but the methods of the subclass will no longer be overriding base class methods. These methods will become independent methods in their own right.  Main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled. This means one cannot be used independent of each other.