/*1. Program to perform mathematical operations. Create a class called AddSub
with methods to add and subtract. Create another class called MulDiv that
extends from AddSub class to use the member data of the super class. MulDiv
should have methods to multiply and divide A main function should access
the methods and perform the mathematical operations.*/
class addsub
{
int num1;
int num2;
addsub(int n1, int n2)
{
num1 = n1;
num2 = n2;
}
int add()
{
return num1+num2;
}
int sub()
{
return num1-num2;
}
}
class multdiv extends addsub
{
public multdiv(int n1, int n2)
{
super(n1, n2);
}
int mul()
{
return num1*num2;
}
float div()
{
return num2/num1;
}
public void display()
{
System.out.println("Number 1 :" + num1);
System.out.println("Number 2 :" + num2);
}
}
public class adsb
{ public static void main(String arg[])
{
addsub r1=new addsub(50,20);
int ad = r1.add();
int sb = r1.sub();
System.out.println("Addition =" +ad);
System.out.println("Subtraction =" +sb);
multdiv r2 =new multdiv(4,20);
int ml = r2.mul();
float dv =r2.div();
System.out.println("Multiply =" +ml);
System.out.println("Division =" +dv);}
}