Mcq - Data Types In Java
21. What is the range of short data type in Java?
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;
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?
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?
Explanation: Range of float data type is -(3.4e38) To +(3.4e38)
25. Which data type value is returned by all transcendental math functions?
26. Which of these coding types is used for data type characters in Java?
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?
Explanation: Boolean can only be assigned true or false literals.
28. What is the output of this program?
output: $ javac array_output.java
$ java array_output
i i i i i
29. Which of these is long data type literal?
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 &?
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 :