Q-2) Given the following code: 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 c) Give the output when this program is run: 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); Complete the missing lines in a and b a) Name the superclass the subclass b) Suppose we wish to save the program in a text file My_Calculation. The extension should be d) Which objects (variables and methods) are inherited from the superclass? e) If you instantiate demo as Calculation demo = new My_Calculation(); in the main program, what happens?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
Q-2) Given the following code:
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
c) Give the output when this program is run:
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);
Complete the missing lines in a and b
a) Name the superclass
the subclass
b) Suppose we wish to save the program in a text file My_Calculation. The extension should be
d) Which objects (variables and methods) are inherited from the superclass?
e) If you instantiate demo as Calculation demo = new My_Calculation(); in the main program, what
happens?
Transcribed Image Text:Q-2) Given the following code: 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 c) Give the output when this program is run: 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); Complete the missing lines in a and b a) Name the superclass the subclass b) Suppose we wish to save the program in a text file My_Calculation. The extension should be d) Which objects (variables and methods) are inherited from the superclass? e) If you instantiate demo as Calculation demo = new My_Calculation(); in the main program, what happens?
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT