Java - MCQ
Multiple Choice Questions
Java MCQ - Introduction to Java - Set 14
66. Which of these can not be used for a variable name in Java?
A). identifier
B). keyword
C). identifier & keyword
D). none of the mentioned
View Answer
Correct: B
67. What will be the output of the following Java program?
class variable_scope
{
public static void main(String args[])
{
int x;
x = 5;
{
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}
}
A). 5 6 5 6
B). 5 6 5
C). Runtime error
D). Compilation error
View Answer
Correct: D
68. Which of these is an incorrect string literal?
A). “Hello World”
B). “Hello\nWorld”
C). “\”Hello World\””
D). "Hello world"
View Answer
Correct: D
69. Which of these is necessary condition for automatic type conversion in Java?
A). The destination type is smaller than source type
B). The destination type is larger than source type
C). The destination type can be larger or smaller than source type
D). None of the mentioned
View Answer
Correct: B
70. What will be the error in the following Java code?
byte b = 50;
b = b * 50;
A). b cannot contain value 100, limited by its range
B). * operator has converted b * 50 into int, which can not be converted to byte without casting
C). b cannot contain value 50
D). No error in this code
View Answer
Correct: B