Java - Data Types MCQ Questions
21. What is the range of short data type in Java?
A. -128 to 127
B. -32768 to 32767
C. -2147483648 to 2147483647
D. None of the mentioned
View Answer
Ans : B
Explanation: Short occupies 16 bits in memory. Its range is from -32768 to 32767.
22. Which of the following are legal lines of Java code?
  1. int w = (int)888.8;
  2. byte x = (byte)100L;
  3. long y = (byte)100;
  4. byte z = (byte)100L;
A. 1 and 2
B. 2 and 3
C. 3 and 4
D. All statements are correct
View Answer
Ans : D
Explanation: Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point number (a double in this case) is cast to an int, it simply loses the digits after the decimal. (2) and (4) are correct because a long can be cast into a byte. If the long is over 127, it loses its most significant (leftmost) bits. (3) actually works, even though a cast is not necessary, because a long can store a byte.
23. An expression involving byte, int, and literal numbers is promoted to which of these?
A. int
B. byte
C. long
D. float
View Answer
Ans : A
Explanation: An expression involving bytes, ints, shorts, literal numbers, the entire expression is promoted to int before any calculation is done.
24. Which of these literals can be contained in float data type variable?
A. -1.7e+308
B. -3.4E+38
C. +1.7e+308
D. -3.4E+50
View Answer
Ans : B
Explanation: Range of float data type is -(3.4e38) To +(3.4e38)
25. Which data type value is returned by all transcendental math functions?
A. int
B. float
C. double
D. long
View Answer
Ans : C
Explanation: None.
26. Which of these coding types is used for data type characters in Java?
A. ASCII
B. ISO-LATIN-1
C. UNICODE
D. None of the mentioned
View Answer
Ans : C
Explanation: Unicode defines fully international character set that can represent all the characters found in all human languages. Its range is from 0 to 65536.
27. Which one is a valid declaration of a boolean?
A. boolean b1 = 1;
B. boolean b2 = ‘false’;
C. boolean b3 = false;
D. boolean b4 = ‘true’
View Answer
Ans : C
Explanation: Boolean can only be assigned true or false literals.
28. What is the output of this program?
class array_output {
public static void main(String args[])
{
char array_variable [] = new char[10];
for (int i = 0; i < 10; ++i) {
array_variable[i] = 'i';
System.out.print(array_variable[i] + """" );
i++;
}
}
}
A. i i i i i
B. 0 1 2 3 4
C. i j k l m
D. None of the mentioned
View Answer
Ans : A
Explanation: None.
output:
$ javac array_output.java
$ java array_output
i i i i i
29. Which of these is long data type literal?
A. 0x99fffL
B. ABCDEFG
C. 0x99fffa
D. 99671246
View Answer
Ans : A
Explanation: Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadecimal long literal.
30. Which of these can be returned by the operator &?
A. Integer
B. Boolean
C. Character
D. Integer or Boolean
View Answer
Ans : D
Explanation: We can use binary ampersand operator on integers/chars (and it returns an integer) or on booleans (and it returns a boolean).
Also check :
Discussion