Java Quiz Exam Oriented - Part 1
Let us see few Java Questions and the respective answers which will be asked frequently:
Answers are marked in light yellow.
Question 1: What is the output of this program?class main_class {
public static void main(String args[])
{
int x = 9;
if (x == 9) {
int x = 8;
System.out.println(x);
} } }Select one:
a. 8
b. compilation error
c. 9
d. runtime error
Question 2: Which of the following is a method having same name as that of it's class?
Select one:
a. delete
b. finalize
c. class
d. constructor
a. delete
b. finalize
c. class
d. constructor
Question 3: Which of these operators is used to allocate memory for an object?
Select One:
a. give
b. alloc
c. malloc
d. new
b. alloc
c. malloc
d. new
Question 4: Which three are valid declarations of a char?
1 char c1 = 064770;2 char c2 = 'face';3 char c3 = 0xbeef;4 char c4 = \u0022;5 char c5 = '\iface';6 char c6 = '\uface';
Select one:
a. 1, 3, 6
b. 5 only
c. 3, 5
d. 1, 2, 4
a. 1, 3, 6
b. 5 only
c. 3, 5
d. 1, 2, 4
Question 5: Which of these lines of code will give better performance?
1. a | 4 + c >> b & 7;
2. (a | ((( 4 * c ) >> b ) & 7 ))Select one:
1. a | 4 + c >> b & 7;
2. (a | ((( 4 * c ) >> b ) & 7 ))Select one:
a. Dependent on the computer system.
b. 2 will give better performance as it has parentheses.
c. 1 will give better performance as it has no parentheses.
d. Both 1 & 2 will give equal performance.
b. 2 will give better performance as it has parentheses.
c. 1 will give better performance as it has no parentheses.
d. Both 1 & 2 will give equal performance.
Question 6: What is the output for the below code ?
public class Test {
public static void main(String[] args){
int i = 010;
int j = 07;
System.out.println(i);
System.out.println(j);
}
}Select one:
public class Test {
public static void main(String[] args){
int i = 010;
int j = 07;
System.out.println(i);
System.out.println(j);
}
}Select one:
a. 8 7
b. 10 7
c. Compilation fails with an error at line 3
d. Compilation fails with an error at line 5
b. 10 7
c. Compilation fails with an error at line 3
d. Compilation fails with an error at line 5
Question 7: Which of these selection statements test only for equality?
Select one:
a. switch
b. none of the mentioned
c. if
d. if and switch
a. switch
b. none of the mentioned
c. if
d. if and switch
Question 8: Which one of these lists contains only Java programming language keywords?
Select one:
a. class, if, void, long, Int, continue
b. goto, instanceof, native, finally, default, throws
c. byte, break, assert, switch, include
d. try, virtual, throw, final, volatile, transient
e. strictfp, constant, super, implements, do
b. goto, instanceof, native, finally, default, throws
c. byte, break, assert, switch, include
d. try, virtual, throw, final, volatile, transient
e. strictfp, constant, super, implements, do
More Questions are available in series
Java Quiz Question and Answers - Part 1