Constructor Shadowing
An Item class defines a private field and initializes it using a constructor parameter with the same name.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
Item i = new Item(5);
System.out.print(i.getValue());
}
}
class Item {
private int value;
public Item(int value) {
this.value = value + 10;
}
public int getValue() {
return value;
}
}
A
15
B
5
C
0
D
10
Question Leaderboard
Not enough data yet to show leaderboard.
