Share this post on:

Inheritance in java is a mechanism in one object acquires all the properties and behavior of a parent object. In Inheritance we can built new class upon an existing class.

Advantages of inheritance are:

  1. Code reusability
  2. Runtime Polymorhism
  3. Rediability Increase

There are Five Types of Inheritance:

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
  5. Hybrid

example:

public class Exampleinheritance {
int a,b;
public void add()
{
    a=5;
    b=6;
    System.out.println(a+b);
}
}
class Second extends Exampleinheritance
{
public void sub()
{
System.out.println(a-b);
}
public static void main(String[] args)
{
Second x1=new Second();
x1.add();x1.sub();
}
}
Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

One Comment

  1. Pingback: What are Important topics in java for Interview? - ArzaTechs

Leave a Comment

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