Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
What is the number displayed when the following program is compiled and run.
class test {
public static void main(String args[]) {
test test1 = new test();
System.out.println(test1.xyz(100));
}
public int xyz(int num) {
if(num == 1) return 1;
else return(xyz(num-1) + num);
}
}
(A) 4040
(B) 5050
(C) 4045
(D) 5055
Ques 2 :
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 3 :
Which statement is true?
(A) ArrayList is a sub class of Vector
(B) HashTable is a sub class of Dictionary
(C) LinkedList is a subclass of ArrayList
(D) Vector is a subclass of Stack
Ques 4 :
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 5 :
The width in bits of double primitive type in Java is --. Select the one correct answer.
(A) The width of double is platform dependent
(B) 64
(C) 128
(D) 8
Ques 6 :
Which of these are legal array declarations or definitions?
(A) int[] []x[];
(B) int x[5];
(C) int *x;
(D) None of above
Ques 7 :
What is the range of values that can be specified for an int. Select the one correct answer.
(A) The range of values is compiler dependent.
(B) -231 to 231 - 1
(C) 231-1 to 231
(D) -215 to 215 - 1
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 :
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 10 :
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 11 :
Which of the following statements is preferred to create a string "Welcome to Java Programming"?
(A) String str = â??Welcome to Java Programmingâ??
(B) String str = new String( â??Welcome to Java Programmingâ?? )
(C) String str; str = â??Welcome to Java Programmingâ??
(D) String str; str = new String (â??Welcome to Java Programmingâ?? )
Ques 12 :
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 13 :
public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
(A) "odd" will always be output.
(B) "even" will always be output.
(C) Compilation fails.
(D) "odd" will be output for odd values of x, and "even" for even values.
Ques 14 :
Which of these are not legal identifiers.
(A) 1alpha
(B) xy+abc
(C) both A and B
(D) None of the above
Ques 15 :
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 16 :
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 17 :
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 18 :
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 19 :
At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
(A) Before statement labeled 1
(B) Before statement labeled 2
(C) Before statement labeled 3
(D) Before statement labeled 4
Ques 20 :
Which of the following statements is true?
(A) The default char data type is a space( â?? â?? ) character.
(B) The default integer data type is â??longâ?? and real data type is â??floatâ??
(C) The default integer data type is â??intâ?? and real data type is â??doubleâ??
(D) The default integer data type is â??intâ?? and real data type is â??floatâ??
Submit Answer
Don't Refresh the Page !! ...