Oracle
1Z0-851 · Question #74
Given: class ClassA { public int numberOfInstances; protected ClassA(int numberOfInstances) { this.numberOfInstances = numberOfInstances; } } public class ExtendedA extends ClassA { private…
The correct answer is A. 420 is the output. See the full explanation below for the reasoning.
Question
Given: class ClassA { public int numberOfInstances; protected ClassA(int numberOfInstances) { this.numberOfInstances = numberOfInstances; } } public class ExtendedA extends ClassA { private ExtendedA(int numberOfInstances) { super(numberOfInstances); } public static void main(String[] args) { ExtendedA ext = new ExtendedA(420); System.out.print(ext.numberOfInstances); } } Which statement is true?
Options
- A420 is the output.
- BAn exception is thrown at runtime.
- CAll constructors must be declared public.
- DConstructors CANNOT use the private modifier.
- EConstructors CANNOT use the protected modifier.
How the community answered
(14 responses)- A71% (10)
- B7% (1)
- C14% (2)
- D7% (1)
Community Discussion
No community discussion yet for this question.