This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instance/Local variable, please help

 
Paula Jiang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

answer is compilation error at line 2 because the variable firstArray has not been initialized before use.
I agree if those are local variable. But if firstArray is the instance variable, it will be initialized to null, and the code compiles fine. So my question is: if they labeled 1,2,3 means those lines must be together? Is this kind of question will be on the real exam? What do they try to test?
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- you are right to be concerned about this question, but no, you will not see something this ambiguous on the real exam
The convention for the exam is to use a numbering scheme that looks like:
* If the numbering starts with '1', you are seeing a complete listing.
* If the numbering starts with some arbitrary number (that is NOT '1'), you are seeing a 'snippet' rather than a complete listing.
For example:
1. class Foo {
2. void go() { }
3. }
The code above is a complete listing.
But...
4. void go() {
5. doStuff();
6. }
The code above is NOT a complete listing. Now, I believe your question is, "if the numbers are consecutive, does that mean they MUST be together?" (in which case, you could infer that the variable is NOT an instance variable, and is in fact a LOCAL variable and thus would not compile). My answer is... probably. If the numbers are together in sequence, I would assume the code is in order.
But I don't believe we have any questions like your example on the real exam. If there were a question like that, it would be wrapped inside a method, and you would SEE the method definition, so that there would be NO confusion that the code you are seeing DOES go together.
We have lots and lots of confusing questions, but I don't believe there are any that attempt to make you *guess* whether the code is in a method or not.
Cheers!
-Kathy
 
Paula Jiang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Kathy! BTW, I love your SCJP book! I recommended to my colleague.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic