Easy Tutorial
For Competitive Exams

Java Programming Variables Test Yourself

1441.Which of the following is correct statement?
Boolean true value is 1 and false value is 0
Every private class has a wrapper class
Constant identifier precede with a reserved word final
System.out.println() method also flushes the buffer
Explanation:
Constants are not directly supported by Java. The reserved Final is used to declare constant.
1442.Size of an integer can be
3 bytes
4 bytes
5 bytes
6 bytes
1443.For which of the following data types the ValueOf() method is NOT overloaded in the string class?
Float
Boolean
Object
None of these
Explanation:
For all Java built in types ValueOf() method is overloaded within the String.
valueOf() method returns the string representation of the corresponding arguments value.
1444.Integer is a
Adapter class
Inner class
Not a class
Wrapper class
Explanation:
Byte, Short, Integer, Long, Character, Boolean, Double, Float are called wrapper class in Java.
1445.Which of the following variable declaration would not compile in Java program?
int VAR;
int var1;
int 1_var;
All are correct
Explanation:
It is illegal to declare a variable name by using integer in the start place.
1446.Among these expressions, which is(are) of type String?
"0"
0
a. and b.
None of these
Explanation:
"0" is correct. Because String literals are enclosed within double quotes.
1447.Which of the following line will not compile assuming b1, b2 and b3 are byte variables and J is Int variable?
b1 = 3;
b3 = b1 * b2;
b3 = 10 * b1;
b2 = (byte) j;
Explanation:
10 is an integer variable and b1 is a byte variable.
The multiplication of these two results an integer variable which cannot be stored in b3
1448.Which are the valid declarations for an integer literal? (i) 0 (ii) -5 (iii) 0416 (iv) 0xabcdef
(i) and (ii)
(i), (ii) and (iii)
(iv)
All of these
Explanation:
Answer: Option D All are valid integer literals.
1449.Which one does not have a valueOf(String) method?
Integer
Boolean
Long
Short
Explanation:

Java Data Type Short does not have a ValueOf(String) method.
The other data types Integer, Boolean, Long, Char, Float, Double have support for the ValueOf(String) method.
1450.Which of the following is NOT an example of a data type?
int
public
boolean
double
Explanation:
public is not a data type.
It is a Java Access modifier.
The other Access modifiers are private and protected.
1451.Int, long, byte, short are the data types of _____data types?
unsigned
signed
both a. and b.
None of these
Explanation:
No Explanation
1452.Which of the following is correct?
int a = 16, a>>2 = 4
int b = -8, b>>1 = -4
int a = 16, a>>>2 = 4
All of the above
Explanation:
No Explanation
1453.Which of the following is the mutable wrapper class?
Integer
BigInteger
Boolean
Character
Explanation:
Java wrapper classes are immutable. BiInteger are mutable.
1454.What is the range of data type short in Java?
-128 to 127
-32768 to 32767
-2147483648 to 2147483647
None of the mentioned
Explanation:

Short occupies 16 bits in memory. Its range is from -32768 to 32767.
1455.What is the range of data type byte in Java?
-128 to 127
-32768 to 32767
-2147483648 to 2147483647
None of the mentioned
Explanation:

Byte occupies 8 bits in memory. Its range is from -128 to 127.
1456.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;
1 and 2
2 and 3
3 and 4
All statements are correct.
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.
1457.An expression involving byte, int, and literal numbers is promoted to which of these?
int
long
byte
float
Explanation:

An expression involving bytes, ints, shorts, literal numbers, the entire expression is promoted to int before any calculation is done.
1458.18. Which of these literals can be contained in a data type float variable?
1.7e-308
3.4e-038
1.7e+308
3.4e-050
Explanation:

Range of data type float is 3.4e-038 to 3.4e+308.
1459.Which data type value is returned by all transcendental math functions?
int
float
double
long
Explanation:

None.
1460.What is the output of this program?
class average {
public static void main(String args[])
{
double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
double result;
result = 0;
for (int i = 0; i < 6; ++i)
result = result + num[i];
System.out.print(result/6);
}
}
16.34
16.566666644
16.46666666666667
16.46666666666666
Explanation:

output:
$ javac average.java
$ java average
16.46666666666667
Share with Friends