• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

boolean

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Upto now i am thinking that
boolean b1;
boolean b2 = false;
Actually both r resulting the same value na.i.e.,initially boolean value is false.So why we r initialiging false.(I found in Mughals)
Is there any thing wrong then pl correct me.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Automatic initialization is done only for member variables, although it does not hurt to explicitly initialize them. Local variables, on the other hand, have to be explicitly initialized before they are used. Array elements are always initialized regardless of whether they are member variables or local variables.
hth,
Junilu

[This message has been edited by JUNILU LACAR (edited June 01, 2001).]
 
Anupama Kota
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Junilu
Public class member
{
boolean b1;
}
other
boolean b2;

So,b1 is automatically initialized,but b2 is not we have to explicitly initialize for it.
But i found in Mughals Pg.62 no initialization, it is false.It is not a mamber variable.
So that only i got doubt that why initialization required.Pl clear my doubt?
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anupama.
boolean b;
boolean b1=false;
these both statement will result in value false assigned to these variables.
But if these variables are local variables of a method then the variables are not initialized to their default values so if u declare a variable within a method u have to explicitly initialize it.
If the variable is instance/class variable of a class then it is automatically assigned the default value. Default value for boolean type is false.
I hope it helps.
Neeraj Thakkar
------------------
Neeraj Thakkar
Sun Certified Programmer for Java 2 Platform
 
Anupama Kota
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Neeraj
Yes,I came to know that if it is not initialized in method it give Compiler Error "Variable may not have been intialized"
Thank U
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic