Inheritance In Java -10 Program

  • Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
  • Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
  • Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.
  • Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.

Types of inheritance in java

We will see all in details:

Single Inheritance Example

When a class inherits another class, it is known as a single inheritance. In the example given below, Dog class inherits the Animal class, so there is the single inheritance.

barking...eating...

Multilevel Inheritance Example

When there is a chain of inheritance, it is known as multilevel inheritance. As you can see in the example given below, BabyDog class inherits the Dog class which again inherits the Animal class, so there is a multilevel inheritance.

Program 4:Multilevel Inheritance Level exampleFilename:multilevel.javaCODE:
}}OUTPUT:weeping...barking...eating...Program 5:Multilevel Inheritacen exampleCODE:
OUTPUT:

Hierarchical Inheritance Example

When two or more classes inherits a single class, it is known as hierarchical inheritance. In the example given below, Dog and Cat classes inherits the Animal class, so there is hierarchical inheritance.

Program 6: Hierarchical Inheritance Example

Filename: Hirarchial.java

meowing...eating...

Why multiple inheritance is not supported in java?

We will see through program

Compile Time Error
SachinforSachin
truetruetrue
No of gears are 3speed of bicycle is 100seat height is 25Thank you.I hope Inheritance in java and its type clear.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store