Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
The class Hashtable is used to implement which collection interface. Select the one correct answer.
(A) List
(B) Set
(C) Map
(D) SortedSet
Ques 2 :
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 3 :
Which of the following are valid constructors within a class Test. Select the two correct answers.
a.
test() { }
b.
Test() { }
c.
void Test() { }
d.
private final Test() { }
e.
abstract Test() { }
f.
Test(Test t) { }
g.
Test(void) { }
(A) b, d
(B) c, f
(C) b, c
(D) b, f
Ques 4 :
class Test
{
public static void main(String [] args) throws Exception
{
Vector data = new Vector();
data.add("apple");
data.add("mango");
data.add("papaya");
data.add("cherry");
data.add("banana");
data.add("apple");
System.out.println(getData(data));
}
public static Vector getData(Vector v)
{
return new Vector(new HashSet(v));
}
}
What would be the output?
(A) Compile Error
(B) [banana, cherry, papaya, apple, mango]
(C) [banana, cherry, papaya, apple, mango]
(D) [banana, cherry, papaya, apple, apple, mango]
Ques 5 :
What happens when the following program is compiled and executed with the command - java test. Select the one correct answer.
class test
{
public static void main(String args[])
{
if(args.length > 0)
System.out.println(args.length);
}
}
(A) The program compiles and runs but does not print anything.
(B) The program compiles and runs and prints 0
(C) The program compiles and runs and prints 1
(D) The program compiles and runs and prints 2
Ques 6 :
What will be the output of the program?
class Exc0 extends Exception { }
class Exc1 extends Exc0 { } /* Line 2 */
public class Test
{
public static void main(String args[])
{
try
{
throw new Exc1(); /* Line 9 */
}
catch (Exc0 e0) /* Line 11 */
{
System.out.println("Ex0 caught");
}
catch (Exception e)
{
System.out.println("exception caught");
}
}
}
(A) Ex0 caught
(B) exception caught
(C) Compilation fails because of an error at line 2.
(D) Compilation fails because of an error at line 9.
Ques 7 :
What is the name of collection interface used to maintain unique elements.
(A) List
(B) Set
(C) Map
(D) All of above
Ques 8 :
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 9 :
What would be the results of compiling and running the following class. Select the one correct answer.
class test
{
public static void main()
{
System.out.println("test");
}
}
(A) The program compiles and runs but does not generate any output.
(B) The program compiles and runs generating an output of "test"
(C) The program compiles but does not run.
(D) The program does not compile as there is no main method defined
Ques 10 :
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;
x = -3 >> 1;
x = x >>> 2;
x = x << 1;
System.out.println(x);
}
}
(A) 7
(B) 23
(C) 5
(D) 2147483646
Ques 11 :
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 12 :
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 13 :
Which operator is used to perform bitwise exclusive or.
(A) &
(B) ^
(C) |
(D) !
Ques 14 :
Which are true in case of interface?
(A) we can create object implementation to an interface
(B) all type of modifiers are allowed to an interface
(C) we instantiate an interface directly
(D) we can mark interface as final
Ques 15 :
The initial value of an instance variable of type String that is not explicitly initialized in the program is --. Select the one correct answer.
(A) null
(B) ""
(C) NULL
(D) The instance variable must be explicitly assigned.
Ques 16 :
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 17 :
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 18 :
Which all lines are part of the output when the following code is compiled and run. Select the nine correct answers.
public class test {
public static void main(String args[]) {
for(int i = 0; i < 3; i++) {
for(int j = 3; j >= 0; j--) {
if(i == j) continue;
System.out.println(i + " " + j);
}
}
}
}
a.
0 0
b.
0 1
c.
0 2
d.
0 3
e.
1 0
f.
1 1
g.
1 2
h.
1 3
i.
2 0
j.
2 1
k.
2 2
l.
2 3
(A) a, b, c, d, e, i, j, k, l
(B) b, c, d, e, g, h, i, j, l
(C) b, c, e, j, k, l, f, h, i
(D) c, d, e, f, g, h, i
Ques 19 :
Which of these are legal identifiers.
(A) number_1
(B) number_a
(C) $1234
(D) All of the above.
Ques 20 :
Which of the following statements are correct. Select the four correct answers.
a.
A Java program must have a package statement.
b.
A package statement if present must be the first statement of the program (barring any comments).
c.
If a Java program defines both a package and import statement, then the import statement must come before the package statement.
d.
An empty file is a valid source file.
e.
A Java file without any class or interface definitions can also be compiled.
f.
If an import statement is present, it must appear before any class or interface definitions.
(A) b, d, e, f
(B) a, b, d, f
(C) d, e, a, c
(D) c, d, b, a
Submit Answer
Don't Refresh the Page !! ...