Multiple choice technology programming languages

Given: 1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ... 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.)

  1. Change line 2 to:public int a;

  2. Change line 2 to:protected int a;

  3. Change line 13 to:public Sub() { this(5); }

  4. Change line 13 to:public Sub() { super(5); }

Reveal answer Fill a bubble to check yourself
C,D Correct answer
Explanation

The problem is that Sub's no-arg constructor tries to access private field a from Super. The issue is visibility. Option C fixes it by calling this(5), which invokes the other constructor Sub(int a), which calls super(a) - the Super constructor sets a. Option D fixes it with super(5), calling Super's constructor directly. Options A and B change visibility of a to public/protected, but that alone doesn't fix the compilation error because the no-arg constructor still can't access a properly without calling a constructor chain.