Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
Select the one correct answer. The number of characters in an object of a class String is given by
(A) The member variable called size
(B) The member variable called length
(C) The method size() returns the number of characters.
(D) The method length() returns the number of characters.
Ques 2 :
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 3 :
Which of these are core interfaces in the collection framework. Select the one correct answer.
(A) Tree
(B) Array
(C) LinkedList
(D) Map
Ques 4 :
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 5 :
Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class.
(A) The method converts an integer to a String.
(B) The method is used to convert String to an integer, assuming that the String represents an integer.
(C) The method is used to convert String to Integer class, assuming that the String represents an integer.
(D) The method converts the Integer object to a String.
Ques 6 :
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 = 3 & 5;
y = 3 | 5;
System.out.println(x + " " + y);
}
}
(A) 7 1
(B) 3 7
(C) 1 7
(D) 1 3
Ques 7 :
The class Hashtable is used to implement which collection interface. Select the one correct answer.
(A) List
(B) Set
(C) Map
(D) SortedSet
Ques 8 :
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 9 :
What is the name of collection interface used to maintain unique elements.
(A) List
(B) Set
(C) Map
(D) All of above
Ques 10 :
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 11 :
What is the minimum value of char type. Select the one correct answer.
(A) 0
(B) -215
(C) -28
(D) -215 - 1
Ques 12 :
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 13 :
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 14 :
What gets printed when the following program is compiled and run? Select the one correct answer.
class xyz {
static int i;
public static void main(String args[]) {
while (i < 0) {
i--;
}
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 15 :
Given two non-negative integers a and b and a String str, what is the number of characters in the expression str.substring(a,b) . Select the one correct answer.
(A) a + b
(B) a - b
(C) b - a
(D) b - a - 1
Ques 16 :
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 17 :
Which of the following is correct? Select the two correct answers.
a.
The native keyword indicates that the method is implemented in another
language like C/C++.
b.
The only statements that can appear before an import statement in a
Java file are comments.
c.
The method definitions inside interfaces are public and abstract. They
cannot be private or protected.
d.
A class constructor may have public or protected keyword before them,
nothing else.
(A) a, b
(B) a, c
(C) b, c
(D) c, d
Ques 18 :
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 19 :
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 20 :
Which of the following is a Java keyword. Select the four correct answers.
a.
extern
b.
synchronized
c.
volatile
d.
friend
e.
friendly
f.
transient
g.
this
h.
then
(A) b, c
(B) b, c, f, g
(C) e, g, h
(D) all of above.
Submit Answer
Don't Refresh the Page !! ...