Assignment: Module 03- Part 03
![]() |
Write a class ConsParamPass and create the constructors to accept the parameters to find addition and subtraction of any two numbers and display it.
Input :
4
5
Output :
9
-1
Here is the code for a ConsParamPass class that creates constructors to accept parameters to find the addition and subtraction of two numbers and display it:
class ConsParamPass {
int a, b, c, d;
ConsParamPass(int x, int y) {
a = x;
b = y;
c = a + b;
d = a - b;
}
void display() {
System.out.println("Addition is: " + c);
System.out.println("Subtraction is: " + d);
}
public static void main(String args[]) {
ConsParamPass obj = new ConsParamPass(4, 5);
obj.display();
}
}
And here is the output:
Addition is: 9
Subtraction is: -1