Single Inheritance 


source file name: singledemo.java

class A

{

void sum(int a, int b)

{

System.out.println("addition ="+(a+b));

}

}

class B extends A

{

void sub(int a, int b)

{

System.out.println("subtraction ="+(a-b));

}

}

class singledemo

{

public static void main(String as[])

{

System.out.println("Inheritance Program");

B ob=new B();

ob.sum(10,20);

ob.sub(100,20);

}

}

output:

E:\JAVA\inheritance>javac singledemo.java

E:\JAVA\inheritance>java singledemo

Inheritance Program

addition =30

subtraction =80