File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Instance/Local variable, please help 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 "Instance/Local variable, please help" Watch "Instance/Local variable, please help" New topic
Author

Instance/Local variable, please help

Paula Jiang
Greenhorn

Joined: Feb 15, 2003
Posts: 15

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?


SCJP2 1.4 (96%) SCWCD(96%)
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
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

Joined: Feb 15, 2003
Posts: 15
Thank you very much Kathy! BTW, I love your SCJP book! I recommended to my colleague.
 
 
subject: Instance/Local variable, please help
 
Similar Threads
Instantiation levels?
problems with interface java
Can't resolve compiler error message
Constructing multidimensional arrays
mock exam questions