Question 3 What will be the output of the depicted program?
Sigmoid technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What will be the output of the depicted program?
class Main {
public static void increment(int number) {
number++;
System.out.println("Inside function: " + number);
}
public static void main(String[] args) {
int number = 5;
increment(number);
System.out.println("After function: " + number);
}
}
Analyze the given choices and select the correct option.
**MCQ
Show answer & explanation
Answer: B. B) Inside function: 6
Java passes primitives by value. Modifying 'number' inside the function alters the local copy (printing 6), while the variable in main remains 5.
Step-by-step Derivation:
Step 1: 'number = 5' in main.
Step 2: increment(number) receives a copy of value 5.
Step 3: Local copy incremented to 6, prints 'Inside function: 6'.
Step 4: Main's variable is unchanged, prints 'After function: 5'.