Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 8

Given:

1. abstract class Shape {

2. Shape ( ) { System.out.println ("Shape"); }

3. protected void area ( ) { System.out.println ("Shape"); }

4. }

5.

6. class Square extends Shape {

7. int side;

8. Square int side {

9. /* insert code here */

10. this.side = side;

11. }

12. public void area ( ) { System.out.println ("Square"); }

13. }

14. class Rectangle extends Square {

15. int len, br;

16. Rectangle (int x, int y) {

17. /* insert code here */

18. len = x, br = y;

19. }

20. void area ( ) { System.out.println ("Rectangle"); }

21. }

Which two modifications enable the code to compile? (Choose two.)

    Correct Answer: D, F

    To enable the code to compile, two modifications are necessary. First, in 'Rectangle' class, when calling the superclass constructor, the correct modification is to insert 'super(x);' at line 17. This is because the 'Square' class does not have a no-argument constructor and requires 'side' to be initialized. Secondly, the 'area' method in 'Rectangle' class must match the access level of the method it overrides from its superclass to maintain visibility. Therefore, 'public' should be used before 'void area()' at line 20.

Discussion
Tarik2190Options: DF

Answer is D,F abstract class Shape { Shape () { System.out.println ("Shape"); } protected void area () { System.out.println ("Shape"); } } class Square extends Shape { int side; Square (int side){ this.side = side; } public void area ( ) { System.out.println ("Square"); } } class Rectangle extends Square { int len, br; Rectangle (int x, int y) { super(x); len = x; br = y; } public void area ( ) { System.out.println ("Rectangle"); } }

bnagaraja9099Options: DF

Options: D,F

r1muka5Options: DF

Correct answer: D (class square does not have default constructor) and F (overriden method is less visible)

asdfjhfgjuaDCVOptions: DF

D and F is the correct answer

steefaandOptions: DF

D and F are correct since class Square doesnt have no-arg constructor because there is one desifned which takes argument and overriding method cant reduce method visibility.

Eden0516Options: DF

Correct answer: D, F (Tested)

WilsonKKerllOptions: DF

Correct answer is D, F.