Results 1 to 3 of 3
Thread: initialization value problem
- 01-28-2008, 08:46 AM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
initialization value problem
Hi,
I am confused about the initialization values in Java. I tried the following code and got an error:
Exception:Java Code:boolean flag; System.out.println("Printing boolean flag's value: " + flag);
I assumed that flag will have false in it. I tried a boolean array and it had false in all the indexes by default.Java Code:The local variable flag may not have been initialized
Please guide me.
Thanks a lot.
- 01-28-2008, 08:57 AM #2
Member
- Join Date
- Nov 2007
- Posts
- 15
- Rep Power
- 0
hmm..
it depends on what you want.. if you want it to be false in the start of your program, initialize it..
boolean flag=false;
- 01-28-2008, 10:54 AM #3
This behavior doesnot work with local variables .. If you have code like this then it will be perfectly okay
Java Code:public class NativeTypeInitializationDemo { public boolean flag; NativeTypeInitializationDemo(){ System.out.println("apple" + flag); } public static void main(String[] args){ new NativeTypeInitializationDemo(); } }dont worry newbie, we got you covered.
Similar Threads
-
Initialization and re-assignment of arrays
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:38 PM -
How to use Initialization callbacks in Spring Framework
By Java Tip in forum Java TipReplies: 0Last Post: 03-31-2008, 10:16 AM -
Icon initialization problem
By saz25 in forum AWT / SwingReplies: 1Last Post: 12-24-2007, 10:37 PM -
Lazy Initialization
By onegcr in forum New To JavaReplies: 1Last Post: 08-14-2007, 03:29 PM -
log4j initialization
By arfatkhan in forum Web FrameworksReplies: 3Last Post: 08-10-2007, 07:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks