java assignment interface

a. Write a program that declares two classes. The parent class is called Simple that has two data members a and b to store two numbers. It has four member functions: 

a. The Add() function adds two numbers and displays the result.
b. The Sub() function subtracts two numbers and display the result.
 c. The Mul() function multiples two numbers and display the result
d. The div() function is used to divide two numbers and displays the result. 

The child class is called Complex that overrides all four functions. Each function

Answer a:

interface Simple{
       public static final int a = 0;
       public static final int b = 0;
       public int  add(int a ,int b);
       public int  sub(int a ,int b);
       public float  div(int a ,int b);
       public int  mul(int a ,int b);}

class Complex implements Simple{

       @Override
       public int add(int a, int b) {
              return a+b;
       }

       @Override
       public int sub(int a, int b) {
              return a-b;
       }

       @Override
       public float div(int a, int b) {
              return a/b;
       }
       @Override
       public int mul(int a, int b) {
              return a*b;
       }
      
}
public class Nasir_FA16_BEE_149 {
public static void main(String args[]) {
       int a=5,b=3;
       Complex c=new Complex();
       System.out.println(c.add(a, b));
       System.out.println(c.mul(a, b));
       System.out.println(c.div(a, b));
       System.out.println(c.sub(a, b));
}
}

Output

Comments