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

0

Assignment: Module 03- Part 03

Write a class ConsCallmeth and call add() method from the constructor of the class and display the addition of two values.
Assignment: Module 03- Part 03

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

Input: 

a = 5 b = 6

Output:  

11

Here is the code for a ConsCallmeth class that calls the add() method from the constructor and displays the addition of two values:




class ConsCallmeth {
    int a, b, c;
  
    ConsCallmeth() {
        a = 5;
        b = 6;
        c = add();
    }
  
    int add() {
        return a + b;
    }
  
    void display() {
        System.out.println("Addition is: " + c);
    }
  
    public static void main(String args[]) {
        ConsCallmeth obj = new ConsCallmeth();
        obj.display();
    }
}   

And here is the output:



Addition is: 11  

👉Write a class DefaultAccount to display the account details already assigned using default constructor 👈

Post a Comment

0Comments
Post a Comment (0)

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

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