Each chapter of the book ends with a Certification Practice question that's comparable to what you could expect to be asked on a Java certification test. Here's the answer for chapter 21:
Answer (d) is correct. The compiler fails with the error message "incompatible types. found: java.lang.StringBuffer. required: java.util.String." The packField() method returns a String. The line could be fixed by changing it to return spaces.toString();
Answer (a) is incorrect. Though this book consistently defines arrays by placing brackets ("") next to the class or data type, that's a style convention rather than a requirement of the language. You can create arrays in Java by placing brackets next to the name of the variable.
Answer (b) is incorrect. Any of the three parts of a for statement can be omitted in Java. In this example, because the class has an instance variable called i, it can be used as the iterator of the for loop. (Though admittedly, this is an unusual thing to do.)
Answer (c) is incorrect. The StringBuffer class can be called with no arguments, which creates a StringBuffer object that does not hold any characters yet.