Writing Methods

AP Computer Science A· difficulty 2/5

public class C {
    public int max(int a, int b) {
        if (a > b) return a;
        return b;
    }
}
// ...
C c = new C();
System.out.println(c.max(4, 9));

What is printed?

  • A

    0

  • B

    13

  • C

    4

  • D

    9

    check_circle

Explanation

Since 4 is not greater than 9, the second return executes and returns 9.

Want 10 more like this — adaptive to your weak spots?

Related questions