Java OCA OCP Practice Question 2682

Question

Given:

2. class Shape {  
3.   protected static String s = "";  
4.   final void grow() { s += "grow "; }  
5.   static final void growFast() { s += "fast "; }  
6. }  
7. public class Square extends Shape {  
8.   void grow() { s += "t-grow "; }  
9.   void growFast() { s+= "t-fast "; }  
10. } 

Which are the FEWEST change(s) required for this code to compile? (Choose all that apply.)

  • A. s must be marked public.
  • B. Square.grow() must be marked final.
  • C. Shape.grow() must NOT be marked final.
  • D. Shape.growFast() must NOT be marked final.
  • E. Shape.growFast() must NOT be marked static.
  • F. Square.growFast() must be removed from the class.


C and F are correct.

Note

Square can already access s.

If Shape.grow() is NOT final, then Square can override it.

In order for Shape.growFast() to be overridden, two changes (D and E), must occur, so for this question, it would require FEWER changes to remove Square.growFast() and not attempt an override.

We don't like this kind of question either, but you may encounter some like it on the real exam.




PreviousNext

Related