Knowee
Questions
Features
Study Tools

class Calculator {    public static int add(int a, int b) {        return a + b;    }    public static int add(int a, int b, int c) {        return a + b + c;    }}public class Main {    public static void main(String[] args) {        int result1 = Calculator.add(10, 20);        int result2 = Calculator.add(10, 20, 30);        System.out.println("Result1: " + result1 + ", Result2: " + result2);    }}a.Result1: 30, Result2: 60b.Result1: 20, Result2: 30c.None of the aboved.Compilation Error

Question

class Calculator {    public static int add(int a, int b) {        return a + b;    }    public static int add(int a, int b, int c) {        return a + b + c;    }}public class Main {    public static void main(String[] args) {        int result1 = Calculator.add(10, 20);        int result2 = Calculator.add(10, 20, 30);        System.out.println("Result1: " + result1 + ", Result2: " + result2);    }}a.Result1: 30, Result2: 60b.Result1: 20, Result2: 30c.None of the aboved.Compilation Error

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is a. Result1: 30, Result2: 60.

This is because in the Main class, the add method of the Calculator class is called twice. The first time, it's called with two arguments (10 and 20), which triggers the first add method in the Calculator class (which adds two integers together). The result (30) is stored in result1.

The second time, the add method is called with three arguments (10, 20, and 30), which triggers the second add method in the Calculator class (which adds three integers together). The result (60) is stored in result2.

Finally, the results are printed out, so the output of the program would be "Result1: 30, Result2: 60".

This problem has been solved

Similar Questions

Select the correct answerWhat will be the output of the following Java program? class static_out { static int x; static int y; void add(int a , int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } }Options7 9 6 67 79 7

Select the correct answerWhat will be the output of the following Java program? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } }Options3 22 31 21 5

Select the correct answerWhat will be the output of the following Java program? class access { static int x; void increment() { x++; } } class static_use { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.increment(); obj2.increment(); System.out.println(obj1.x + " " + obj2.x); } }Options 2 21 11 2Compilation Error

What is the output of the following code?1. public class A {2. int add(int i, int j){3. return i+j;4. }5. }6. public class B extends A{7. public static void main(String argv[]){ 8. short s = 9;9. System.out.println(add(s,6));10. }11.}

public class testmeth{static int i = 1;public static void main(String args[]){System.out.println(i+” , “);m(i);System.out.println(i);}public void m(int i){i += 2;}}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.