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 BookSurge.com.
Are you a university student studying Java programming? Do you agree that my book would serve as a helpful workbook and companion to be used along with the Java fundamentals textbook that is currently being used in your class? If so, then please ask your professor to consider using my book in future classes.
If you have any questions or comments concerning my mock exams or my book, then please send an e-mail to me at scjpexam2000@yahoo.com.
I would also like to read your response to the following questions.
| 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. |