This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan' s Question !

 
Vinod Sinha
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 5
class MWC105 {
static boolean b1;
public static void main(String[] args) {
boolean[] array = new boolean[1];
boolean b2;
System.out.print(b1+",");
System.out.print(array[0]+",");
System.out.print(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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks
Harwinder
[ October 19, 2003: Message edited by: Harwinder Bhatia ]
 
Doug Dunn
Author
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the actual compiler error:
Test.java:8: variable b2 might not have been initialized
System.out.print(b2);
^
1 error
This is a simple definite assignment problem
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic