Sunday, August 15, 2010

Access Modifiers: Word.java

Courtesy of Sun Web Learning Center

11. public interface Word { boolean isSpelled(String w); }
12.
13. abstract class Verb1 implements Word { boolean isSpelled() { } }
14.
15. abstract class Verb2 implements Word { boolean isSpelled() { return true; } }
16.
17. abstract class Verb3 implements Word {
18.   boolean isSpelled(String w) { return true; }
19. }


What is the result?

A     Compilation succeeds.
B     Compilation fails due only to an error on line 13.
C     Compilation fails due only to an error on line 15.
D     Compilation fails due only to an error on line 18.
E     Compilation fails due only to errors on lines 13 and 15.
F     Compilation fails due only to errors on lines 13 and 18.
G     Compilation fails due only to errors on lines 15 and 18.


F is correct. Verb1's isSpelled() method is missing a return statement, and Verb3 fails attempting to assign weaker access privileges to isSpelled().

No comments:

Post a Comment