Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
What happens when the following program is compiled and then the command "java check it out" is executed. Select the one correct answer.
class check
{
public static void main(String args[])
{
System.out.println(args[args.length-2]);
}
}
(A) The program compiles but generates ArrayIndexOutOfBoundsException exception
(B) The program prints java
(C) The program prints check
(D) The program prints it
Ques 2 :
What happens when the following program is compiled and run. Select the one correct answer.
public class example
{
int i[] = {0};
public static void main(String args[])
{
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[])
{
i[0] = 2;
i[0] *= 2;
}
}
(A) The program prints 0
(B) The program prints 1.
(C) The program prints 2
(D) The program prints 4.
Ques 3 :
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the two correct answers.
a.
void method() { }
b.
int method() { return 0;}
c.
void method(int i) { }
d.
private void method() { }
(A) b, c
(B) a, d
(C) a, c
(D) b, d
Ques 4 :
What all gets printed when the following program is compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
int i, j=1;
i = (j>1)?2:1;
switch(i) {
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}
a.
0
b.
1
c.
2
d.
3
(A) a, b
(B) b, c
(C) c, b
(D) c, d
Ques 5 :
What is the result of compiling and running the following class. Select the one correct answer.
class Test
{
public void methodA(int i)
{
System.out.println(i);
}
public int methodA(int i)
{
System.out.println(i+1);
return i+1;
}
public static void main(String args[])
{
Test X = new Test();
X.methodA(5);
}
}
Select the one correct answer.
(A) The program compiles and runs printing 5.
(B) The program compiles and runs printing 6.
(C) The program gives runtime exception because it does not find the method Test.methodA(int)
(D) The program give compilation error because methodA is defined twice in class Test.
Ques 6 :
Which of the assignment are not valid.
(A) short s = 28;
(B) float f = 2.3;
(C) double d = 2.3;
(D) int I = '1';
Ques 7 :
To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer.
(A) By using the keyword public before the variable.
(B) By using the keyword protected before the variable.
(C) By using the keyword private before the variable.
(D) The variable should not be preceded by any of the above mentioned keywords.
Ques 8 :
Which statement is true regarding the creation of default constructor?
(A) The default constructor initializes local variables.
(B) The default constructor invokes the constructor of the superclass.
(C) The default constructor initializes the instance variables declared in the class.
(D) When class has only constructor with parameter, the compiler creates a Default constructor
Ques 9 :
Which of the following statements is true?
(A) An exception can be thrown by throw keyword explicitly.
(B) An exception can be thrown by throws keyword explicitly.
Ques 10 :
Which code determines the int value data closer to, but not greater than, a double value b?
(A) Int data = (int) Math.floor(b);
(B) Int data = (int) Math.abs(b);
(C) Int data = (int) Math.ceil(b);
(D) Int data = (int) Math.min(b);
Ques 11 :
A program needs to store the name, salary, and age of employees in years. Which of the following data types should be used to create the Employee class. Select the three correct answers.
a.
char
b.
boolean
c.
Boolean
d.
String
e.
int
f.
double
(A) a,d,f
(B) a,e,f
(C) d,e,f
(D) d,a,e
Ques 12 :
Why @SupressWarning Annotation is used?
(A) To suppress exception issued by compiler
(B) To show warnings
(C) To show exceptions
(D) To suppress exception issued by compiler
Ques 13 :
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[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
(A) 1 2
(B) 1 3
(C) 1 4
(D) 2 4
Ques 14 :
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 15 :
A top level class may have only the following access modifier. Select the one correct answer.
(A) package
(B) protected
(C) private
(D) public
Ques 16 :
Using up to four characters, write the Java representation of integer literal 3 in hexadecimal.
(A) 0x03, 0X03, 0X3
(B) 0x04, 0X04, 0X4
(C) 0x05, 0X05, 0X5
(D) none of these
Ques 17 :
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 18 :
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[]) {
boolean x = false;
int a;
if(x) a = x ? 1: 2;
else a = x ? 3: 4;
System.out.println(a);
}
}
(A) 1
(B) 2
(C) 3
(D) 4
Ques 19 :
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 20 :
The class java.lang.Exception is ?
(A) protected
(B) implements Throwable
(C) serializable
(D) extends Throwable
Submit Answer
Don't Refresh the Page !! ...