wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Chapter 3 Self Test Q.7 K & B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Chapter 3 Self Test Q.7 K & B" Watch "Chapter 3 Self Test Q.7 K & B" New topic
Author

Chapter 3 Self Test Q.7 K & B

Gerald Backmeister
Greenhorn

Joined: May 02, 2008
Posts: 2
Hi,

I was very surprised about the answer for question 7... I was very sure, that the compilation fails, because the String array x was not initialized.

Here is the code:

1. class Zippy {
2. String[] x;
3. int[] a [] = {{1, 2}, {1}};
4. Object c = new long[4];
5. Object[] d = x;
6. }

The answer A ("Compilation succeeds") was given to be correct, but I think, that compilation fails at line 5. I tried it out and the compiler really breaks with an error at line 5.

Can anyone tell me, if I'm right or wrong?

I searched the forum and the errata, but I didn't find anything about this point.


Thanks & Regards,
Gerald
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I tried it out and the compiler really breaks with an error at line 5.

Really ? What did the compiler say ? Can you post the error message ?


[My Blog]
All roads lead to JavaRanch
Gerald Backmeister
Greenhorn

Joined: May 02, 2008
Posts: 2
Ooops. My fault. I made the mistake to paste the declaration lines into a method, so they all are local variables and have to be initialized before usage.

Sorry + Thanks,
Gerald
 
 
subject: Chapter 3 Self Test Q.7 K & B
 
Similar Threads
Clarification for 1 question from K and B book - Chapter 8 - Inner classes.
Question in K&B Chapter 8
Please explain this array question to me
Inner Classes
not initialized