The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.
Today, you can find my book at amazon.com.
| No. | Answer | Remark | |
|---|---|---|---|
| 1 | f | Compile-time error | Variables declared inside of a block or method are called local variables; they are not automatically initialized. The compiler will generate an error as a result of the attempt to access the local variables before a value has been assigned. |
| 2 | e | Compile-time error at line 5. | The local variable y has not been initialized so the attempt to access the variable results in a compile-time error. |
| 3 | c | Prints: 0null | The numeric sum of variables a, b, c, d and e is zero. The zero is converted to a String and concatenated with s. |
| 4 | a | Prints: 0,0,0,0,0,null | The default value of type char is the null character. When it is cast to an int the value is interpreted as zero. |
| 5 | c | Prints: 0,0.0,0.0,false,null | Generally speaking, numeric type variables are initialized to zero. Primitive boolean variables are initialized to false. Reference type variables are initialized to null. |
| 6 | c | Compile-time error | Local variables are not initialized automatically, and must be initialized explicitly before attempting to access the value. The local variable i3 will not be initialized if i1 is less than or equal to zero; so the result is a compile-time error. |
| 7 | f | Compile-time error at line 4. | Anytime a field is accessed from within a static context it is very important to verify that the field is also static. If the field is instead an instance variable then the result is a Compile-time error. |