0% found this document useful (0 votes)
2 views13 pages

Inheritance

The document presents an overview of inheritance in Object-Oriented Programming (OOP), detailing its definition, features, and various types including single, multiple, multilevel, hierarchical, and hybrid inheritance. It emphasizes key concepts such as code reusability, method overriding, and the use of keywords like 'extends' and 'super'. The document also includes examples to illustrate each type of inheritance.

Uploaded by

pkpappu2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

Inheritance

The document presents an overview of inheritance in Object-Oriented Programming (OOP), detailing its definition, features, and various types including single, multiple, multilevel, hierarchical, and hybrid inheritance. It emphasizes key concepts such as code reusability, method overriding, and the use of keywords like 'extends' and 'super'. The document also includes examples to illustrate each type of inheritance.

Uploaded by

pkpappu2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INHERITANCE

Presented By :- Pappu Kumar


Enrollment NO:- 0191CY241029
Agenda :-
❖Introduction
❖Features
❖Keywords & Syntaxes
❖Types
❖Single Inheritance
❖Multiple Inheritance
❖Multilevel Inheritance
❖Hierarchical Inheritance
❖Hybrid Inheritance
❖Q&A
What is inheritance ?
• Inheritance is an Object-Oriented Programming (OOP) feature
that allows one class (called the child class or subclass) to
acquire the properties (data members) and methods (functions) of
another class (called the parent class or superclass).
Features of inheritance :-
➢Code Reusability :- ➢Method Overriding
Common Fields And Methods Live A Child Class Can
Once In The Parent Class And Are Redefine A Parent’s
Reused By Every Child Class. Method To Provide Its Own
Specific Behaviour.

➢ Hierarchical Classification ➢Extensibility


Classes Can Be Organized From New Functionality Can Be
General (Parent) To Specific (Child), Added In A Sub Class
Mirroring Real-world Taxonomies. Without Modifying The
Existing Parent Class.
Keywords & Syntax :-
❖ extends
Used by a subclass to inherit from a superclass

class Animal {
void eat() { ... }
❖super }
Refers to the immediate parent class; calls its
constructor or methods. class Dog extends Animal {
Dog() {
super(); // calls
Animal()
❖implements }
Used by a class to inherit from an interface. void bark() { ... }
}
Types of Inheritance

01 02 03 04 05
Single Multiple Multilevel Hierarchical Hybrid
One child, one parent One child, many parents Chain of derivation Many children, one Combination of types
(By Class) (By Interface) (By Class) parent. (By Interface)
(By Class)
Single Inheritance
• One subclass inherits from exactly one
superclass — the simplest and most
common form.
Vehicle

Example
class Vehicle { }
class Car extends
Vehicle { }
Car
Multiple inheritance
• One subclass inherits from two or more
superclasses at once. Java doesn't allow
this for classes (to avoid ambiguity) but Flyer Swimmer

supports it through interfaces.

Example
interface Flyer { void fly(); } Duck
interface Swimmer { void swim(); }
class Duck implements Flyer, Swimmer { }
Multilevel Inheritance
• A class is derived from a class that is itself
derived from another class — forming a Animal

chain of inheritance.

Dog

Example
class Animal { }
class Dog extends Animal { }
class Puppy extends Dog { } Puppy
Hierarchical Inheritance
• Two or more subclasses inherit from the
same single superclass, each specializing
Shape
it differently.

Example
class Shape { }
Circle Square Triangle
class Circle extends Shape { }
class Square extends Shape { }
class Triangle extends Shape { }
Hybrid Inheritance
• A combination of two or more types of Shape
inheritance in a single hierarchy — for
example, hierarchical plus multilevel.

Circle Square

Example
class Shape { }
ColoredSquare
class Circle extends Shape { }
class Square extends Shape { }
class ColoredSquare extends Square { }
Questions?
let's discuss Inheritance

You might also like