OOPS - Inheritance in java programming language

navindecr23 10 views 22 slides Oct 19, 2025
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

Hello there from IT student(KRCE),India i created an inheritance in java, kindly do some animations on debugging slides because pdf doesnt support lol. Hope i cover enough concepts of it


Slide Content

INHERITANCE
IN JAVA PROGRAMMINGDone By NAVIN PRASATH R

Table of
Contents
What is
inheritance?
1
Why we use?
2
Types of
Inheritance
3
4
Debugging
5
FAQs

WHAT IS
INHERITANCE?
Definition:
Inheritance is a mechanism in Java where one class (child/subclass/)
acquires the properties and behaviors (fields & methods) of another class
(parent/superclass/Baseclass).
We use “extends” keyword
Child Class Parent Class
C Extends P
class Parent {
// parent class code
}
class Child extends Parent {
// child class code
}

Code Reusability: Avoid rewriting common logic.
Readability & Maintenance: Easier to update and manage.
Extensibility: Build on existing classes.
Polymorphism Support: Enables method overriding and dynamic method
dispatch.
WHY WE USE
INHERITANCE?
Inherits
Eg: Sound()
The child class cat Inherits the functions
of the parent class Animal.
Such as sound(), eat(),walk() etc..,

Single Inheritance
Multi-level Inheritance
Hierarchical inheritance
Hybrid Inheritance
Multiple inheritance
TYPES OF
INHERITANCE

It inherites only one parent’s
class properties
SINGLE
class Animal {
void eat() {
System.out.println("Eating...");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Barking...");
}
}
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
d.eat();
d.bark();
}
}
OUTPUT:
Eating...
Barking...

A class inherits from a class
that itself is a child
MULTI-LEVEL
class Animal {
void eat() { System.out.println("Eating..."); }
}
class Dog extends Animal {
void bark() { System.out.println("Barking..."); }
}
class Puppy extends Dog {
void weep() { System.out.println("Weeping..."); }
}
public class Main {
public static void main(String[] args) {
Puppy p = new Puppy();
p.eat();
p.bark();
p.weep();
}
}
OUTPUT:
Eating...
Barking...
Weeping...

Multiple classes inherit from a
single parent
Hierarchical
class Animal {
void eat() { System.out.println("Eating..."); }
}
class Dog extends Animal {
void bark() { System.out.println("Barking..."); }
}
class Cat extends Animal {
void meow() { System.out.println("Meowing..."); }
}
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
Cat c = new Cat();
d.eat(); d.bark();
c.eat(); c.meow();
}
}
OUTPUT:
Eating...
Barking...
Eating...
Meowing...

It is a mix of two or more of the
above types of inheritance.
In Java, we can achieve hybrid
inheritance only through
Interfaces.
HYBRID

In Multiple inheritances, one
class can have more than one
super class and inherit
features from all parent
classes and achieved only
through interfaces.
MULTIPLE

class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Dog {
void bark() { System.out.println("Barking"); }
}
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
d.sound();
}
}
DEBUGGING
class A {
private int num = 10;
}
class B extends A {
void show() { System.out.println(num); }
}
public class Main {
public static void main(String[] args) {
B b = new B();
b.show();
}
}
class A {
final void show() { System.out.println("Final show"); }
}
class B extends A {
void show() { System.out.println("Override show"); }
}
class A {
void display() { System.out.println("A"); }
}
class B extends A { }
class C extends B { }
public class Main {
public static void main(String[] args) {
C obj = new C();
obj.display();
}
}

Error Happens Because the
extends keyword is missing
DEBUGGING
class A {
private int num = 10;
}
class B extends A {
void show() { System.out.println(num); }
}
public class Main {
public static void main(String[] args) {
B b = new B();
b.show();
}
}
class A {
final void show() { System.out.println("Final show"); }
}
class B extends A {
void show() { System.out.println("Override show"); }
}
class A {
void display() { System.out.println("A"); }
}
class B extends A { }
class C extends B { }
public class Main {
public static void main(String[] args) {
C obj = new C();
obj.display();
}
}

Error Happens Because the
extends keyword is missing
DEBUGGING
class A {
private int num = 10;
}
class B extends A {
void show() { System.out.println(num); }
}
public class Main {
public static void main(String[] args) {
B b = new B();
b.show();
}
}
class A {
final void show() { System.out.println("Final show"); }
}
class B extends A {
void show() { System.out.println("Override show"); }
}
Output :
A

DEBUGGING
Error Happens Because,
num is private in class A → not
accessible in B.
class A {
final void show() { System.out.println("Final show"); }
}
class B extends A {
void show() { System.out.println("Override show"); }
}
Output :
A
Error Happens Because the
extends keyword is missing

DEBUGGING
Error Happens Because,
num is private in class A → not
accessible in B.
Error Happens Because, final
methods cannot be
overridden.
Error Happens Because the
extends keyword is missing
Output :
A

FAQs
Q2: Can we achieve multiple inheritance in Java?
Q1: What keyword is used for inheritance in Java?
Q4: Can a subclass inherit private members of its parent class?
Q3: What is hierarchical inheritance?

FAQs
Q2: Can we achieve multiple inheritance in Java?
Q1: What keyword is used for inheritance in Java?
The extends is used for class inheritance
Q4: Can a subclass inherit private members of its parent class?
Q3: What is hierarchical inheritance?

FAQs
Q2: Can we achieve multiple inheritance in Java?
Only through interfaces, not classes.
Q1: What keyword is used for inheritance in Java?
Q4: Can a subclass inherit private members of its parent class?
Q3: What is hierarchical inheritance?
The extends is used for class inheritance

FAQs
Q2: Can we achieve multiple inheritance in Java?
Only through interfaces, not classes.
Q1: What keyword is used for inheritance in Java?
Q4: Can a subclass inherit private members of its parent class?
Q3: What is hierarchical inheritance?
When multiple classes inherit from a single superclass.
Example: Dog and Cat both extend Animal.
The extends is used for class inheritance

FAQs
Q4: Can a subclass inherit private members of its parent class?
Q2: Can we achieve multiple inheritance in Java?
Q3: What is hierarchical inheritance?
No, private members are not inherited directly.
Only through interfaces, not classes.
When multiple classes inherit from a single superclass.
Example: Dog and Cat both extend Animal.
Q1: What keyword is used for inheritance in Java?
The extends is used for class inheritance

ANY QUERIES?
FEEL FREE TO ASK!

THE END
THANK YOU FOR LISTENINGDone By NAVIN PRASATH R