Write a class ConsParamPass and create the constructors to accept the parameters to find addition and subtraction of any two numbers and display it.

0

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.
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   

👉Write a class ConsCallmeth and call add() method from the constructor of the class and display the addition of two values. 👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates