File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan' s Question ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic

Dan' s Question !

Vinod Sinha
Ranch Hand

Joined: Oct 16, 2003
Posts: 43
Question 5
class MWC105 {
static boolean b1;
public static void main(String[] args) {
boolean[] array = new boolean[1];
boolean b2;
What is the result of attempting to compile and run the program?
a. Prints: true,true,true
b. Prints: false,false,false
c. Prints: null,null,null
d. Prints: false,true,false
e. Compile-time error
f. Run-time error
g. None of the above
The answer should be (f) but it is given as (e) ?
Harwinder Bhatia
Ranch Hand

Joined: Oct 17, 2003
Posts: 150
Hi Vinod
The answer is infact (e).
This is what I got when I 'tried' to compile it:

Please remember that local variables are not automatically initialized and have to initialized explicitly before being used in expressions. But elements in an array (local or otherwise) are initialized automatically if not explicitly initialized.
[ October 19, 2003: Message edited by: Harwinder Bhatia ]
Doug Dunn
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
Here is the actual compiler error: variable b2 might not have been initialized
1 error
This is a simple definite assignment problem

Download a copy of <a href="" target="_blank" rel="nofollow"><i>"Mastering The Fundamentals of The Java Programming Language"</i></a>
I agree. Here's the link:
subject: Dan' s Question !
It's not a secret anymore!