Single Inheritance in java Example 2

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

1225

Program:

class Calculator {
   int z;

   public void addition(int x, int y) {
      z = x + y;
      System.out.println("The sum of the given numbers:"+z);
   }

   public void Subtraction(int x, int y) {
      z = x - y;
      System.out.println("The difference between the given numbers:"+z);
   }
}

public class Calculation extends Calculator {
   public void multiplication(int x, int y) {
      z = x * y;
      System.out.println("The product of the given numbers:"+z);
   }

   public static void main(String args[]) {
      int a = 30, b = 20;
      Calculation demo = new Calculation();
      demo.addition(a, b);
      demo.Subtraction(a, b);
      demo.multiplication(a, b);
   }
}

Output:

The sum of the given numbers:50
The difference between the given numbers:10
The product of the given numbers:600
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.