Assignment: Module 03- Part 03
![]() |
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