Java Programming - Language Fundamentals - Discussion

Discussion :: Language Fundamentals - General Questions (Q.No.11)

11. 

Which one is a valid declaration of a boolean?

[A]. boolean b1 = 0;
[B]. boolean b2 = 'false';
[C]. boolean b3 = false;
[D]. boolean b4 = Boolean.false();
[E]. boolean b5 = no;

Answer: Option C

Explanation:

A boolean can only be assigned the literal true or false.

Vineet said: (Mar 10, 2011)  
Please also define the resion of other option, why is not corret.

Saurav said: (Sep 7, 2011)  
Why is option A not correct?

Sweety said: (Sep 25, 2011)  
Boolean always returns true or false. So option A can't be !

Akanksha said: (Nov 9, 2011)  
Option B is have single quotes which is for a string so its wrong.
Option D is compilation error.
Option E is also compilation error as no is not any keyword.

Kirti said: (Feb 3, 2012)  
Option D is not correct because Boolean is not correct it must be Boolean.

Avinash said: (Jan 8, 2013)  
Boolean by default false in java. In java Boolean has only two value false and true. Not (0, 1) like C.

Bishal said: (Oct 30, 2013)  
Boolean default value is false & it also take true but not with any kind of invited comma.

Upendra said: (Nov 7, 2013)  
Answer: C.

Because the Java people had given some default values to all the primitive data type like for int =0; For String=null;.

Amaziane said: (Jun 24, 2014)  
For the option D we can initialize a boolean with this method.

Boolean b = Boolean.FALSE;
Boolean b = Boolean.TRUE;

Anurag said: (Feb 2, 2015)  
Option A is not correct because Boolean value cannot be 0 because it is a long value.

Option B is not correct.

Option D is not correct because there is no class Boolean.

Option E is not correct it should be "true" or "false".

Vinita said: (Jul 5, 2016)  
Why A is not Correct? Answer me clearly.

Neeraja said: (Jul 9, 2016)  
Option A is not correct because in boolean data type it's consists only true or false statement.

Option B also not correct because false is declared within single quotes like string.

So, Option C is right.

Tamisevi said: (Aug 5, 2017)  
Why b is not correct?

Bhanu said: (Feb 24, 2018)  
Either boolean should be true or false nor (0, 1) then why not option A is correct?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.