← 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);
}
}
- A.5
- B.6
- C.0
- 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 →