Objects and Collections

Q1: Which is valid declaration of a float?

A float f = 1F;

B float f = 1.0;

C float f = "1";

D float f = 1.0d;

ANS:A - float f = 1F;

Option A is valid declaration of float. Option B is incorrect because any literal number with a decimal point u declare the computer will implicitly cast to double unless you include "F or f" Option C is incorrect because it is a String. Option D is incorrect because "d" tells the computer it is a double so therefore you are trying to put a double value into a float variable i.e there might be a loss of precision.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.