Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

will if be initialized.  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friend.pls read the code bellowed.
public class exampl{
public Boolean flags[]=new Boolean[4];
public static void main(){
example E=new example();
System.out.println("flag is "+E.flag[1]);
}
}
the given choice is :
A) the text "flag is false" is written out to standard output.
B) the text "flag is null" is written out to standard output.
the given answer is B.
But I think A is right .Because the each element of boolean array will be initialized with a default value ( in this case it is "false")
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
boolean variables will be initialized with the default value
false</false>

the default values of the elements of an uninitialized array is null
hope that helps
Samith.P.Nambiar
<pre>
\```/
(o o) harder u try luckier u get
-------oOO--(_)--OOo----------------------------
</pre>
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please notice the difference b/w boolean(primitive type) & Boolean( a Wrapper class already defined in java.lang pkg.).
Default value for boolean type reference variable is false.
whereas that for Boolean type reference variable is null.
hope this helps
Lusha
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean variables will be initialized with the default value
false</false>
the default values of the elements of an uninitialized array is null
// the array is initialized to the default value of the primitive type if the array is of primitive type
// here the array is of type Boolean and not boolean .
boolean is a primitive type
Boolean is an Object
so an unitialized array of objects is initialized to "null"
hope the difference is clear now

samitha please note the difference
[This message has been edited by sona nagee (edited May 29, 2001).]
 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ooops i'm very sorry .... made a mistake in a hurry

as lusha has rightly pointed out:
1. Default value for boolean type reference variable is false.
2. Default value for Boolean type reference variable is null.
now what u have in ur code is an array of Boolean types
Please note that:

uninitialized arrays are initialized to default values of the respective array type
hope that helps
Samith.P.Nambiar
<pre>
\```/
(o o) harder u try luckier u get
-------oOO--(_)--OOo----------------------------
</pre>
 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for pointing that out ... guess we both noticed it at the same time
Samith.P.Nambiar
 
gzw0733
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thanks all the people share the words with me.
That meant Boolean isn't a reserve word,only a type. it is completely different from boolena.
isn't ?
I think I caught your meaning.
 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gzw0733 please re-register with a valid first name and last name according to our naming regualtions. http://www.javaranch.com/name.jsp
[This message has been edited by Angela Poynton (edited May 29, 2001).]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!