SlideShare a Scribd company logo
1 of 10
Download to read offline
Introduction to
Inheritance in Java
Inheritance is a key concept in object-oriented programming (OOP) that
allows a class to inherit properties and behavior from another class. In Java,
inheritance enables the creation of new classes (child classes) that are built
upon existing classes (parent classes). This facilitates code reusability,
promotes a hierarchical structure, and supports polymorphism, which is
essential for building robust and scalable software solutions.
by Bhanu Prakash
BP
Single Inheritance
Definition
Single inheritance in Java refers to the process
where a class inherits properties and behaviors
from a single parent class. This allows the derived
class to reuse the code structure and functionality
of the parent class, enhancing code reusability and
promoting a more organized and efficient
codebase.
Example
An example of single inheritance in Java is the
creation of a class named "Car" that inherits
properties from a class named "Vehicle." The "Car"
class can then add its specific attributes and
behaviors, such as "numberOfWheels" or
"fuelType," while still benefiting from the properties
inherited from "Vehicle."
Multiple Inheritance
Complexity
Unlike single inheritance, multiple inheritance in
Java allows a class to inherit properties and
behaviors from more than one parent class. While
this may seem powerful, it introduces complexities
related to ambiguity in method and variable
inheritance, posing challenges in code
maintenance and understanding.
Resolution
Java does not support multiple inheritance of
classes, but it allows the use of interfaces to
achieve a form of multiple inheritance. By
implementing multiple interfaces, a class can
inherit the abstract methods defined within those
interfaces without encountering the issues
associated with traditional multiple class
inheritance.
Multilevel Inheritance
1 Definition
Multilevel inheritance in Java involves a hierarchy of classes where a derived class
serves as the base class for another class. This creates a chain of inheritance, enabling
the derived classes to inherit properties and behaviors not only from their immediate
parent class but also from the grandparent class and so on.
Hierarchical Inheritance
1 Structure
Hierarchical inheritance in Java represents a structure where multiple classes are derived from a
single parent class. Each derived class in the hierarchy inherits properties and behaviors from the
common parent, allowing for the creation of a unified codebase with shared functionalities.
Hybrid Inheritance
Hybrid Inheritance Combines Multiple Types
Classes Interfaces
Method Overriding in Inheritance
1 Definition
Method overriding refers to the ability of a subclass to provide a specific implementation
of a method that is already present in its parent class. This enables the derived class to
customize the behavior of inherited methods, allowing for flexibility and customization in
the codebase.
Super Keyword in Inheritance
1
Usage
Super keyword is used to access and call the parent
class constructor, methods, and members from the
child class. It provides a way to refer to the
immediate parent class, enabling the child class to
utilize the functionalities inherited from the parent.
2
Example
It is commonly used to initialize the attributes of the
parent class within the constructor of the child class,
ensuring the proper initialization of inherited
properties.
Abstract Classes and Inheritance
1 Abstraction
Abstract classes in Java provide a blueprint for other classes and can be
inherited. They can contain abstract methods that lack a body or concrete
implementation, allowing derived classes to provide specific implementations of
those methods.
2 Polymorphism
By combining abstraction and inheritance, abstract classes promote
polymorphism, allowing classes to be treated as instances of their parent class,
leading to flexibility and code reusability.
Final Keyword and Inheritance
1
Restriction
The final keyword in Java prevents the
inheritance of a class, making it impossible for
other classes to inherit from a final class. This
ensures that the final class's properties and
behavior remain unchanged and unextended.
2
Usage
By marking a class as final, developers can
enforce strict design patterns and restrict the
modification or extension of critical classes,
ensuring security, stability, and code integrity.

More Related Content

Similar to Introduction to Inheritance in Java for presentation

Similar to Introduction to Inheritance in Java for presentation (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptx
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Unit 4
Unit 4Unit 4
Unit 4
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
OOps Interview questions.pdf
OOps Interview questions.pdfOOps Interview questions.pdf
OOps Interview questions.pdf
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Final presentation programming
Final presentation programmingFinal presentation programming
Final presentation programming
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 

Recently uploaded

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Recently uploaded (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Introduction to Inheritance in Java for presentation

  • 1. Introduction to Inheritance in Java Inheritance is a key concept in object-oriented programming (OOP) that allows a class to inherit properties and behavior from another class. In Java, inheritance enables the creation of new classes (child classes) that are built upon existing classes (parent classes). This facilitates code reusability, promotes a hierarchical structure, and supports polymorphism, which is essential for building robust and scalable software solutions. by Bhanu Prakash BP
  • 2. Single Inheritance Definition Single inheritance in Java refers to the process where a class inherits properties and behaviors from a single parent class. This allows the derived class to reuse the code structure and functionality of the parent class, enhancing code reusability and promoting a more organized and efficient codebase. Example An example of single inheritance in Java is the creation of a class named "Car" that inherits properties from a class named "Vehicle." The "Car" class can then add its specific attributes and behaviors, such as "numberOfWheels" or "fuelType," while still benefiting from the properties inherited from "Vehicle."
  • 3. Multiple Inheritance Complexity Unlike single inheritance, multiple inheritance in Java allows a class to inherit properties and behaviors from more than one parent class. While this may seem powerful, it introduces complexities related to ambiguity in method and variable inheritance, posing challenges in code maintenance and understanding. Resolution Java does not support multiple inheritance of classes, but it allows the use of interfaces to achieve a form of multiple inheritance. By implementing multiple interfaces, a class can inherit the abstract methods defined within those interfaces without encountering the issues associated with traditional multiple class inheritance.
  • 4. Multilevel Inheritance 1 Definition Multilevel inheritance in Java involves a hierarchy of classes where a derived class serves as the base class for another class. This creates a chain of inheritance, enabling the derived classes to inherit properties and behaviors not only from their immediate parent class but also from the grandparent class and so on.
  • 5. Hierarchical Inheritance 1 Structure Hierarchical inheritance in Java represents a structure where multiple classes are derived from a single parent class. Each derived class in the hierarchy inherits properties and behaviors from the common parent, allowing for the creation of a unified codebase with shared functionalities.
  • 6. Hybrid Inheritance Hybrid Inheritance Combines Multiple Types Classes Interfaces
  • 7. Method Overriding in Inheritance 1 Definition Method overriding refers to the ability of a subclass to provide a specific implementation of a method that is already present in its parent class. This enables the derived class to customize the behavior of inherited methods, allowing for flexibility and customization in the codebase.
  • 8. Super Keyword in Inheritance 1 Usage Super keyword is used to access and call the parent class constructor, methods, and members from the child class. It provides a way to refer to the immediate parent class, enabling the child class to utilize the functionalities inherited from the parent. 2 Example It is commonly used to initialize the attributes of the parent class within the constructor of the child class, ensuring the proper initialization of inherited properties.
  • 9. Abstract Classes and Inheritance 1 Abstraction Abstract classes in Java provide a blueprint for other classes and can be inherited. They can contain abstract methods that lack a body or concrete implementation, allowing derived classes to provide specific implementations of those methods. 2 Polymorphism By combining abstraction and inheritance, abstract classes promote polymorphism, allowing classes to be treated as instances of their parent class, leading to flexibility and code reusability.
  • 10. Final Keyword and Inheritance 1 Restriction The final keyword in Java prevents the inheritance of a class, making it impossible for other classes to inherit from a final class. This ensures that the final class's properties and behavior remain unchanged and unextended. 2 Usage By marking a class as final, developers can enforce strict design patterns and restrict the modification or extension of critical classes, ensuring security, stability, and code integrity.