Thursday, December 8, 2016

Write a JAVA program that illustrates multi-level inheritance

 Aim: Write a JAVA program that illustrates multi-level inheritance.

Program:

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

public class Multiplication extends Subtract 
{
   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 = 20, b = 10;
      Multiplication demo = new Multiplication();
      demo.addition(a, b);
      demo.Subtraction(a, b);
      demo.multiplication(a, b);
   }
}

Output:


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home