Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 3 Self Test Q.7 K & B

 
Gerald Backmeister
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Gerald Backmeister
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic