Inheritance in Java

Inheritance in java.jpg

What is Inheritance

In Java, a process involving the collection of all the parent object's properties and actions by the child object is known as Inheritance.

The Inheritance cycle is one of the main features of OOP (Object-oriented Programming) through which one class obtains the properties and functionalities of another class.

Parts of Inheritance in Java

  • Class: A class is a set of objects that have common properties. It is a model or a blueprint that creates objects.
  • Super Class: Within this class, whose inherited characteristics are known as superclass (or parent or foundation class).
  • Subclass:  The class inheriting the other class is considered a subclass (or an expanded, or infant class derivative). The subclass must incorporate its own fields and methods, in addition to the superclass fields and methods.

With the help of examples, we'll learn about Java inheritance in this Java tutorial.

Types of Inheritance in java
  • Single
  • Multilevel
  • Hierarchical

Single inheritance is simply the inheritance, where it happens within class only.
Types of Inheritance

Multilevel inheritance In Java language, It is essentially the process when a single class inherits the properties and methods of the multiple classes of different levels.
Types of Inheritance

Hierarchical Inheritance In Java language, It is essentially the situation where one class acts as a superclass with more than one subclass.
Types of Inheritance

Java Inheritance Example

Here is an example of the Java inheritance that will allow you to understand its physical side.

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);  
}  
}

Comments

Popular posts from this blog

C Tutorial

C Programming language Tutorial