Site icon WebArtDeveloper

How to Create a Program to Perform Inheritance in Core Java

In this tutorial how to Perform Class Inheritance in Core Java  is shown.

Code:

InheritanceDemo.java

class A
{
private int a,b;

A()
{
a=b=1;
}

A(int a,int b)
{
this.a=a;
this.b=b;
}

void display()
{
System.out.println(“A: “+a);
System.out.println(“B: “+b);
}

}

class B extends A
{
private int c;

B()
{
super();
c=1;
}

B(int c,int a,int b)
{
super(a,b);
this.c=c;
}

void displayb()
{
display();
System.out.println(“C: “+c);
}
}

public class InheritanceDemo
{
public static void main(String[] args)
{
B b2=new B();
b2.displayb();
B b1=new B(6,7,8);
b1.displayb();
}
}

https://youtu.be/495L_iHs-sM

Exit mobile version