Which of the following lines will compile without errors and warnings?
Explanation
 
float f = 1.3; // 1.3 constant is of type double. Therefore, 1.3f should be used
int i = 10; // Ok
char c = "a"; // Char constants should be written in single quotation marks: 'a';
byte b = 255; // byte range varies from -128 to 127
boolean b = null; // null value is acceptable only for reference types
 

Yes it gives an error when I write like boolean b = null

2017 Feb 24, 9:47:46 AM

Actually it should! Check it out : https://ideone.com/NIgAA4 . "boolean" is a primitive type, it can not be assigned with null value

2016 Jun 20, 3:26:18 PM

When I run boolean b = null I get no errors.

2016 Jun 16, 6:48:31 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes