Given:
2. class Shape { 3. private Shape() { } 4. protected Shape(int x) { } 5. } // ww w .ja v a 2 s. co m 6. public class Main extends Shape { 7. // Main(int x) { } 8. // Main(int x) { super(); } 9. // Main(int x) { super(x); } 10. // private Main(int x) { super(x); } 11. // Main() { } 12. // Main() { this(); } 13. // Main() { this(6); } 14. // Main() { super(7); } 15. public static void main(String[] args) { 16. new Main(7); 17. new Main(); 18. } }
Which sets of constructors can be uncommented for the code to compile? (Choose all that apply.)
F and H are correct.
None of the constructors can chain to Shape's private constructor, they must all get to Shape's protected constructor somehow.
Lines 7 and 8 won't ever work because Shape's protected constructor needs an argument.
Line 13 would work with either line 9 or line 10.
Line 14 would work with either line 9 or line 10.