Oracle
1Z0-851 · Question #37
Given: 01. class Super { 02. private int a; 03. protected Super(int a) { this.a = a; } 04. } 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. }…
The correct answer is C. Change line 13 to: public Sub() { this(5); } D. Change line 13 to: public Sub() { super(5); }. See the full explanation below for the reasoning.
Question
Given: 01. class Super { 02. private int a; 03. protected Super(int a) { this.a = a; } 04. } 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. } Which two, independently, will allow Sub to compile? (Choose two.)
Options
- AChange line 2 to: public int a;
- BChange line 2 to: protected int a;
- CChange line 13 to: public Sub() { this(5); }
- DChange line 13 to: public Sub() { super(5); }
- EChange line 13 to: public Sub() { super(a); }
How the community answered
(49 responses)- A8% (4)
- B2% (1)
- C86% (42)
- E4% (2)
Community Discussion
No community discussion yet for this question.