Easy Tutorial
For Competitive Exams
Java Programming Variables Test Yourself Page: 2
1461.What is the output of this program?
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d.;
}
}
38 43
39 44
295 300
295.04 300
Explanation:

Type casting a larger variable into a smaller variable results in modulo of larger variable by range of smaller variable.
b contains 300 which is larger than byte’s range i:e -128 to 127 hence d contains 300 modulo 256 i:e 44.
output:
$ javac conversion.java
$ java conversion
39 44
1462.What is the output of this program?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
25
24
32
33
Explanation:

Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.
output:
$ javac increment.java
$ java increment
32
1463.What is the output of this program?
class area {
public static void main(String args[])
{
double r, pi, a;
r = 9.8;
pi = 3.14;
a = pi * r * r;
System.out.println(a);
}
}
301.5656
301
301.56
301.56560000
Explanation:

output:
$ javac area.java
$ java area
301.5656
1464.What is the numerical range of a char in Java?
-128 to 127
0 to 256
0 to 32767
0 to 65535
Explanation:

Char occupies 16-bit in memory, so it supports 2^16 i:e from 0 to 65535.
1465.Which of these coding types is used for data type characters in Java?
ASCII
ISO-LATIN-1
UNICODE
None of the mentioned
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.
1466.Which of these values can a boolean variable contain?
True & False
0 & 1
Any integer value
true
Explanation:

Boolean variable can contain only one of two possible values, true and false.
1467.Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
ASCII
ISO-LATIN-1
None of the mentioned
ASCII and ISO-LATIN1
Explanation:

First 0 to 127 character set in Unicode are same as those of ISO-LAIN-1 and ASCII.
1468.Which one is a valid declaration of a boolean?
boolean b1 = 1;
boolean b2 = ‘false’;
boolean b3 = false;
boolean b4 = ‘true’
Explanation:

Boolean can only be assigned true or false literals.
1469.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++;
}
}
}
i i i i i
0 1 2 3 4
i j k l m
None of the mentioned
Explanation:

output:
$ javac array_output.java
$ java array_output
i i i i i
1470.What is the output of this program?
class mainclass {
public static void main(String args[])
{
char a = A;
a++;
System.out.print((int)a);
}
}
66
67
65
64
Explanation:

ASCII value of ‘A’ is 65, on using ++ operator character value increments by one.
output:
$ javac mainclass.java
$ java mainclass
66
1471.What is the output of this program?
class mainclass {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
if (var1)
System.out.println(var1);
else
System.out.println(var2);
}
}
0
1
true
false
Explanation:

output:
$ javac mainclass.java
$ java mainclass
true
What is the output of this program?
class booloperators {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
System.out.println((var2 & var2));
}
}
Solution:

boolean ‘&’ operator always returns true or false.
var1 is defined true and var2 is defined false hence their ‘&’ operator result is false.
output:
$ javac booloperators.java
$ java booloperators
false
1473.What is the output of this program?
class asciicodes {
public static void main(String args[])
{
char var1 = A;
char var2 = a;
System.out.println((int)var1 + " " + (int)var2);
}
}
162
65 97
67 95
66 98
Explanation:

ASCII code for ‘A’ is 65 and for ‘a’ is 97.
output:
$ javac asciicodes.java
$ java asciicodes
65 97
1474.Which of these is data type long literal?
0x99fffL
ABCDEFG
0x99fffa
99671246
Explanation:

Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadecimal long literal.
1475.Which of these can be returned by the operator & ?
Integer
Boolean
Character
Integer or Boolean
Explanation:

We can use binary ampersand operator on integers/chars (and it returns an integer) or
on booleans (and it returns a boolean).
1476.Literals in java must be preceded by which of these?
L
l
D
L and l
Explanation:

Data type long literals are appended by an upper or lowercase L.
1477.Literal can be of which of these data types?
integer
float
boolean
all of the mentioned
Explanation:

None
1478.Which of these can not be used for a variable name in Java?
identifier
keyword
identifier & keyword
None of the mentioned
Explanation:


Keywords are specially reserved words which can not be used for naming a user defined variable
example : class, int, for etc.
1479.What is the output of this program?
class evaluate {
public static void main(String args[])
{
int a[] = {1,2,3,4,5};
int d[] = a;
int sum = 0;
for (int j = 0; j < 3; ++j)
sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
System.out.println(sum);
}
}
38
39
40
41
Explanation:

None
output:
$ javac evaluate.java
$ java evaluate
40
1480.Which of these is incorrect string literal?
“Hello World”
“Hello”
“World”
ab12
Explanation:
all string literals must within double quotes.
Share with Friends