0% found this document useful (0 votes)
1K views

Java - Inheritance ppt.1-1

This document discusses inheritance in Java. Inheritance allows new classes to be created from existing classes, with the new class called the derived or child class inheriting properties and behavior from the existing or parent class. The document defines different types of inheritance like single, multilevel, multiple, hierarchical and hybrid inheritance. It provides examples and advantages of inheritance like code reusability, organization, extensibility, polymorphism and easier maintenance. The document concludes with a sample Java program demonstrating single inheritance with a Programmer class extending an Employee class.

Uploaded by

Kbraju Cbit
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Java - Inheritance ppt.1-1

This document discusses inheritance in Java. Inheritance allows new classes to be created from existing classes, with the new class called the derived or child class inheriting properties and behavior from the existing or parent class. The document defines different types of inheritance like single, multilevel, multiple, hierarchical and hybrid inheritance. It provides examples and advantages of inheritance like code reusability, organization, extensibility, polymorphism and easier maintenance. The document concludes with a sample Java program demonstrating single inheritance with a Programmer class extending an Employee class.

Uploaded by

Kbraju Cbit
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

INHERITANCE

INSTRUCTOR NAME : K.BASAVARAJU SIR


TEAM MEMBERS:
22EG106B38 NITHYANANDHANA
22EG106B39 MADHUMITHA
22EG106B40 CHANDRAMOULI
22EG106B41 YASHWANTH
22EG106B42 KAVYA
INHERITANCE

 Inheritance is a feature or a process in which, new classes are


created from the existing classes.
 The new class created is called “derived class” or “child class”.
 The existing class is known as the “base class” or “parent class”.
 The child class now is said to be inherited from the parent class.
 The extends keyword is used for inheritance in Java. Using
the extends keyword indicates you are derived from an existing
class.
Types of Inheritance

 Single inheritance
 Multilevel inheritance
 Multiple inheritance
 Hierarchical inheritance
 Hybrid inheritance
Single inheritance

 In single inheritance, a sub-class is


derived from only one super class. It
inherits the properties and behavior of a
single-parent class. Sometimes it is also
known as simple inheritance.
Multilevel inheritance

 In multi-level inheritance, a class is


derived from a class which is also derived
from another class is called multi-level
inheritance.
 In simple words, we can say that a class
that has more than one parent class is
called multi-level inheritance.
 Note that the classes must be at different
levels. Hence, there exists a single base
class and single derived class but multiple
intermediate base classes.
Multiple inheritance

 In multiple inheritance a single


class can inherit from more than

one class.
 Java does not support multiple
inheritances due to ambiguity.
 Java does not support multiple
inheritances at the class level but
can be achieved through
an interface.
 Hierarchical inheritance  Hybrid inheritance
If a number of classes are derived Hybrid means consist of more than
from a single base class, it is one. Hybrid inheritance is the
called hierarchical inheritance. combination of two or more types of
inheritance.
Advantages of inheritance:

 Code Reusability: Inheritance lets you reuse  Polymorphism: Inheritance is essential for
code from an existing class, which means you achieving polymorphism, which allows objects of
don't have to write the same code again. This different classes to be treated as objects of a
saves time and effort. common parent class. This simplifies code and
makes it more flexible.
 Organization: It helps in organizing classes in a
 Maintenance: When you need to make changes to a
hierarchy. You can have a base (parent) class
common feature shared by multiple classes, you can
with common attributes and methods, and then
make the change in the parent class, and it will
create specialized (child) classes that inherit from
automatically reflect in all the child classes. This
the base class and add their unique features. reduces the chances of errors and makes
 Extensibility: You can extend the functionality maintenance easier.
of a class by creating a new class (child class)
that inherits from it and adds or overrides
methods. This makes it easier to make changes
and additions to your code.
Java program to implement inheritance
class Employee
{
float salary=40000;
}
class Programmer extends Employee
{
int bonus=10000;
public static void main(String args[])
{
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}

You might also like