Java OOPS – Part 2 – types of Inheritance with examples


Inheritance is a mechanism wherein a new class (child class) is derived from an existing class (parent class), child classes may inherit or acquire the properties and methods of parent classes.

Types of inheritance

  • Single / multi level inheritance
  • Hierarchical inheritance

Benefits of inheritance

  • Reusability
  • Extensibility
  • Saves time and effort
  • Provides clear model structure

For details, watch here

Code samples

Example – 1

Base Class – Animals

—-Child Class – Cat

—-Child Class – Lion

——–Child Class – Cub

Example – 2

Base Class – BankAcc

—-Child Class – SavingsAcc

——–Child Class – Transactions


Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *