🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Methods: all 10 questions

Quiz: Java Methods · Question 1 of 10

What does this print? (code)

What does this print?

public class Main {
    static void inc(int x) { x++; }
    public static void main(String[] args) {
        int a = 5;
        inc(a);
        System.out.println(a);
    }
}
  1. A.5
  2. B.6
  3. C.0
  4. D.Error
Answer & explanation

Correct answer: 5

The method changes only its own copy of the value.

Can you get the rest right without peeking?

Take the timed Quiz: Java Methods quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →