Question

Add another subclass division to the example below: class Calculation{ int z; public void addition(int x,...

Add another subclass division to the example below:

class Calculation{

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 My_Calculation extends Calculation{

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;

My_Calculation demo = new My_Calculation();

demo.addition(a, b);

demo.Subtraction(a, b);

demo.multiplication(a, b);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Calculation.java :

//Java class
public class Calculation {
   int z;

   // method for addition of two numbers
   public void addition(int x, int y) {
       z = x + y;
       System.out.println("The sum of the given numbers:" + z);
   }
   //method for subtraction of two numbers
   public void Subtraction(int x, int y) {
       z = x - y;
       System.out.println("The difference between the given numbers:" + z);

   }
}

******************************

division.java :

//Java class
public class division extends Calculation {
   //method to divide a number by another number
   public void divide(int x, int y){
       z = x/y;
       System.out.println("The division of the given numbers:"+z);

       }
}
***********************************

My_Calculation.java :

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

   // main method entry point of the program
   public static void main(String args[]) {
       int a = 20, b = 10;// declaring variable
       // creating object of My_Calculation
       My_Calculation demo = new My_Calculation();
       demo.addition(a, b);
       demo.Subtraction(a, b);
       demo.multiplication(a, b);
       //creating object of division
       division d=new division();
       d.divide(a, b);//calling method with division object
   }
}
===============================

Screen 1:

Add a comment
Know the answer?
Add Answer to:
Add another subclass division to the example below: class Calculation{ int z; public void addition(int x,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT