Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
The class java.lang.Exception is ?
(A) protected
(B) implements Throwable
(C) serializable
(D) extends Throwable
Ques 2 :
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,d,c
(B) b,c,a
(C) d,e
(D) a,b
Ques 3 :
Which of the following are legal identifier names in Java. Select the two correct answers.
a.
%abcd
b.
$abcd
c.
1abcd
d.
package
e.
_a_long_name
(A) a, c
(B) b, d
(C) b, e
(D) a, e
Ques 4 :
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 5 :
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int x, y;
x = 5 >> 2;
y = x >>> 2;
System.out.println(y);
}
}
(A) 5
(B) 2
(C) 80
(D) 0
Ques 6 :
Which of the following are keywords in Java.
(A) implement
(B) friend
(C) NULL
(D) synchronized
Ques 7 :
String s = new String("xyz");
Assuming the above declaration, which of the following statements would compile. Select the one correct answer.
(A) s = 2 * s;
(B) int i = s[0];
(C) s = s + s;
(D) s = s >> 2;
Ques 8 :
5.
Which of these are interfaces in the collection framework. Select the two correct answers.
a.
Set
b.
List
c.
Array
d.
Vector
e.
LinkedList
(A) a,b,c
(B) a,b
(C) b,c,d,e
(D) c,d
Ques 9 :
Which of the following are legal definitions of the main method that can be used to execute a class.
(A) public static int main(String args[])
(B) public void main(String args)
(C) public static void main(String args[])
(D) public static void main(string args[])
Ques 10 :
Which of the following are legal Java programs. Select the four correct answers.
a.
// The comments come before the package
package pkg;
import java.awt.*;
class C{}
b.
package pkg;
import java.awt.*;
class C{}
c.
package pkg1;
package pkg2;
import java.awt.*;
class C{}
d.
package pkg;
import java.awt.*;
e.
import java.awt.*;
class C{}
f.
import java.awt.*;
package pkg;
class C {}
(A) a, b, c, d
(B) a, b, d, e
(C) b, c, d, e
(D) c, d, e, f
Ques 11 :
What are the things we have to follow while creating annotations?
(A) methods must not have any throws clauses
(B) methods must not have any parameters
(C) method should return any one of primitive data types
(D) All the above
Ques 12 :
Which of the following statement is true about the assert statement. Select the one correct answer.
(A) If a Java class contains assert statements, then it must be compiled with -1.4 option.
(B) When a program having assertions is run, -assertion option must be specified, otherwise the assertions get ignored.
(C) A possible syntax of assert statement is assert logical_expression If logical_expression evaluates to true, the program generates an AssertionError.
(D) The program terminates on its first AssertionError.
Ques 13 :
Which of these statements are true. Select the two correct answers.
a.
For each try block there must be at least one catch block defined.
b.
A try block may be followed by any number of finally blocks.
c.
A try block must be followed by at least one finally or catch block.
d.
If both catch and finally blocks are defined, catch block must precede the finally block.
(A) a, b
(B) c, d
(C) b, d
(D) a, c
Ques 14 :
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
protected class example {
public static void main(String args[]) {
String test = "abc";
test = test + test;
System.out.println(test);
}
}
(A) The class does not compile because the top level class cannot be protected.
(B) The program prints "abc"
(C) The program prints "abcabc"
(D) The program does not compile because statement "test = test + test" is illegal.
Ques 15 :
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 16 :
A lower precision can be assigned to a higher precision value in Java. For example a byte type data can be assigned to int type.
(A) True
(B) False
Ques 17 :
What gets printed when the following code is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
} while (i > 2);
System.out.println(i);
}
}
(A) 0
(B) 1
(C) 2
(D) -1
Ques 18 :
Which of the following are true. Select the one correct answers.
(A) && operator is used for short-circuited logical AND.
(B) ~ operator is the bit-wise XOR operator.
(C) operator is used to perform bitwise OR and also short-circuited logical OR.
(D) The unsigned right shift operator in Java is >>.
Ques 19 :
Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class.
(A) public
(B) private
(C) protected
(D) default
Ques 20 :
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
Submit Answer
Don't Refresh the Page !! ...