Inheritance Single Type-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

//parent class/super class

package Inheritance;

public class Parentclass


{
public void add()
{
int a=10,b=20;
System.out.println("Addition of two
nos:"+(a+b));
}

public void sub()


{
int a=20,b=10;
System.out.println("Subtraction of two
nos:"+(a-b));
}

public void div()


{
int a=10,b=5;
System.out.println("DIvision of two
nos:"+(a/b));
}

}
//sub class

package Inheritance;

public class subclass extends Parentclass


{
//This is class for area calculation

public void area()


{
int side=5;
System.out.println("Area of square:"+(side*side));
}

//call from main class from other class


package Inheritance;
public class singlelevel_inheritance
{
public static void main(String [] args)
{
subclass s1=new subclass();
System.out.println("***Method of subclass***");

s1.area(); //method of subclass


System.out.println("");
//method call of parent class through subclass
System.out.println("***Methods of super-class***");
s1.add();
s1.sub();
s1.div();
}
}

You might also like