Data Types And Variables(Java Program ) Questions and Answers
Explanation:-
Answer: Option B. -> doublefloating-point numbers are by default of type double.
99.9 is a double not a float.
To print "float" cast 99.9 to (float)
Explanation:-
Answer: Option C. -> 22Static variable have a single copy of memory. That means all the objects will share the same memory location. So, if the object test increase the value of x by 1, then object test1 will access that incremented value of x
Explanation:-
Answer: Option D. -> Compile error - do is not valid identifier.$7 is valid identifier. Identifiers must start with a letter, a currency character ($), or underscore ( _ ). Identifiers cannot start with a number. You can't use a Java keyword as an identifier. do is a Java keyword.
Explanation:-
Answer: Option A. -> 8 7By placing a zero in front of the number is an integer in octal form. 010 is in octal form so its value is 8
Explanation:-
Answer: Option D. -> Compilation fails with an error at line 8i and j are instance variable and attempting to access an instance variable from a static method. So Compilation fails.
Explanation:-
Answer: Option C. -> Compilation fails with an error at line 6int or smaller expressions always resulting in an int. So compiler complain about Type mismatch: cannot convert from int to byte for b = b+7; But b += 7; // No problem because +=, -=, *=, and /= will all put in an implicit cast. b += 7 is same as b = (byte)b+7 so compiler not complain.
Explanation:-
Answer: Option C. -> Compilation fails with an error at line 3byte can only hold up to 127. So compiler complain about possible loss of precision.
static byte MAX_VALUE − This is constant holding the maximum value a byte can have, 27-1.
static byte MIN_VALUE − This is constant holding the minimum value a byte can have, -27.