Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
What gets printed when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
byte x = 3;
x = (byte)~x;
System.out.println(x);
}
}
(A) 0
(B) 3
(C) -4
(D) none of these
Ques 2 :
What would happen when the following is compiled and executed. Select the one correct answer.
class example {
int x;
int y;
String name;
public static void main(String args[]) {
example pnt = new example();
System.out.println("pnt is " + pnt.name +
" " + pnt.x + " " + pnt.y);
}
}
(A) The program does not compile because x, y and name are not initialized.
(B) The program throws a runtime exception as x, y, and name are used before initialization.
(C) The program prints pnt is 0 0.
(D) The program prints pnt is null 0 0.
Ques 3 :
When we go for thread synchronization?
(A) to remove the lock on the thread
(B) when there is a single thread
(C) to make a thread in sleep mode
(D) when we want to prevent any other multiple thread to act an same object
Ques 4 :
What is the result of compiling and running the following program. Select the one correct answer.
class test {
public static void main(String args[]) {
char ch;
String test2 = "abcd";
String test = new String("abcd");
if(test.equals(test2)) {
if(test == test2)
ch = test.charAt(0);
else
ch = test.charAt(1);
}
else {
if(test == test2)
ch = test.charAt(2);
else
ch = test.charAt(3);
}
System.out.println(ch);
}
}
(A) 'a'
(B) 'b'
(C) 'c'
(D) 'd'
Ques 5 :
What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the two correct answers.
public class test
{
public static void main(String args[])
{
System.out.println(args[0]+" "+args.length);
}
}
a.
java
b.
test
c.
lets
d.
3
e.
4
f.
5
g.
6
(A) a, b
(B) c, d
(C) b, e
(D) c, e
Ques 6 :
What all gets printed when the following gets compiled and run. Select the two correct answers.
public class example {
public static void main(String args[]) {
int x = 0;
if(x > 0) x = 1;
switch(x) {
case 1: System.out.println(1);
case 0: System.out.println(0);
case 2: System.out.println(2);
break;
case 3: System.out.println(3);
default: System.out.println(4);
break;
}
}
}
A.
0
B.
1
C.
2
D.
3
E.
4
(A) 1, 0, 2
(B) 3, 4
(C) 0, 2
(D) 1
Ques 7 :
What gets printed when the following program is compiled and run? Select the one correct answer.
class test {
public static void main(String args[]) {
int i;
do {
i++;
}
while(i < 0);
System.out.println(i);
}
}
(A) The program does not compile as i is not initialized.
(B) The program compiles but does not run.
(C) The program compiles and runs but does not print anything.
(D) The program prints 0.
Ques 8 :
Which of these are legal identifiers. Select the three correct answers.
a.
number_1
b.
number_a
c.
$1234
d.
-volatile
(A) a, b, c
(B) a, b
(C) a
(D) b
Ques 9 :
Which operator is used to perform bitwise exclusive or.
(A) &
(B) ^
(C) |
(D) !
Ques 10 :
Which of the following are true. Select the three correct answers.
a.
A static method may be invoked before even a single instance of the class is constructed.
b.
A static method cannot access non-static methods of the class.
c.
Abstract modifier can appear before a class or a method but not before a variable.
d.
final modifier can appear before a class or a variable but not before a method.
E.
Synchronized modifier may appear before a method or a variable but not before a class.
(A) a,b,c
(B) a,b
(C) b,c,d
(D) all of above
Ques 11 :
Which of these are interfaces in the collection framework. Select the two correct answers.
a.
HashMap
b.
ArrayList
c.
Collection
d.
SortedMap
e.
TreeMap
(A) a,b
(B) c,d
(C) d,e
(D) a,d
Ques 12 :
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
(A) BC is printed before exiting with an error
(B) Compilation fails.
(C) ABCD
(D) C is printed before exiting with an error message.
Ques 13 :
What is the minimum value of char type. Select the one correct answer.
(A) 0
(B) -215
(C) -28
(D) -215 - 1
Ques 14 :
How many numeric data types are supported in Java?
(A) 8
(B) 4
(C) 6
(D) 2
Ques 15 :
What all gets printed when the following gets compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
a.
0
b.
1
c.
2
d.
3
e.
4
(A) a, b
(B) b, c
(C) c, d
(D) d, e
Ques 16 :
Given the following declarations, which of the assignments given in the options below would compile. Select the two correct answers.
int i = 5;
boolean t = true;
float f = 2.3F;
double d = 2.3;
a.
t = (boolean) i;
b.
f = d;
c.
d = i;
d.
i = 5;
e.
f = 2.8;
(A) a,b
(B) b,c
(C) c,d
(D) a,d
Ques 17 :
Which of the following are legal declaration and definition of a method. Select all correct answers.
a.
void method() {};
b.
void method(void) {};
c.
method() {};
d.
method(void) {};
e.
void method {};
(A) a,b
(B) a
(C) a,b,c
(D) b,d,e
Ques 18 :
What happens when the following code is compiled and run. Select the one correct answer.
for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i;
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The number 2 gets printed with AssertionError
(D) The number 3 gets printed with AssertionError
Ques 19 :
What happens when the following code is compiled and run. Select the one correct answer.
for(int i = 1; i < 3; i++)
for(int j = 3; j > i; j--)
assert i!=j {System.out.println(i); }
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The program generates a compilation error.
(D) The number 2 gets printed with AssertionError
Ques 20 :
Which of the following statements related to Garbage Collection are correct. Select the two correct answers.
a.
It is possible for a program to free memory at a given time.
b.
Garbage Collection feature of Java ensures that the program never runs out of memory.
c.
It is possible for a program to make an object available for Garbage Collection.
d.
The finalize method of an object is invoked before garbage collection is performed on the object.
(A) a, b
(B) b, d
(C) c, d
(D) b, c
Submit Answer
Don't Refresh the Page !! ...