Ques 1 : Which declaration of the main method below would allow a class to be started as a standalone program.
(A) public static int main(char args[])
(B) public static void main(String args[])
(C) public static void MAIN(String args[])
(D) public static void main(String args)
Answer : public static void main(String args[])
Ques 2 : What is the meaning of the return data type void?
(A) An empty memory space is returned so that the developers can utilize it.
(B) void is not supported in Java
(C) void returns no data type.
(D) null
Answer : void returns no data type.
Ques 3 : Which of these are legal identifiers.
(A) number_1
(B) number_a
(C) $1234
(D) All of the above.
Answer : All of the above.
Ques 4 : Which of the following are Java keywords?
(A) throw
(B) void
(C) private
(D) All of the above.
Answer : All of the above.
Ques 5 : 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
Answer : True
Ques 6 : Which of these are not legal identifiers.
(A) 1alpha
(B) xy+abc
(C) both A and B
(D) None of the above
Answer : both A and B
Ques 7 : 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[])
Answer : public static void main(String args[])
Ques 8 : Which of the following statements about the Java language is true?
(A) Both procedural and OOP are supported in Java.
(B) Java supports only procedural approach towards programming.
(C) Java supports only OOP approach.
(D) None of the above.
Answer : Both procedural and OOP are supported in Java.
Ques 9 : Which of the following are keywords in Java.
(A) implement
(B) friend
(C) NULL
(D) synchronized
Answer : synchronized
Ques 10 : Which of these are legal array declarations or definitions?
(A) int[] []x[];
(B) int x[5];
(C) int *x;
(D) None of above
Answer : int[] []x[];
Ques 11 : What gets printed when the following code is compiled and run with the following command - java test 2 Select the one correct answer.
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
(A) test
(B) test -1
(C) 0
(D) 1
Answer : 1
Description :Note that the program gets one command line argument - 2. args.length will get set to 1. So the condition if(args.length > 1) will fail, and the second check if(args.length > 0) will return true.
Ques 12 : Which of the following statements is false about objects?
(A) An instance of a class is an object
(B) Objects can access both static and instance data
(C) Objects do not permit encapsulation
(D) Object is the super class of all other classes
Answer : Objects do not permit encapsulation
Ques 13 : 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
Answer : a, b, c
Ques 14 : The class Hashtable is used to implement which collection interface. Select the one correct answer.
(A) List
(B) Set
(C) Map
(D) SortedSet
Answer : Map
Description :
The collection interface Map has two implementation HashMap and Hashtable.
Ques 15 : TreeMap class is used to implement which collection interface. Select the one correct answer.
(A) Set
(B) SortedSet
(C) Tree
(D) SortedMap
Answer : SortedMap
Ques 16 : Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer.
(A) arr.length
(B) arr.length - 1
(C) arr.size
(D) arr.length()
Answer : arr.length
Ques 17 : 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 > i; j--)
assert i!=j {System.out.println(i); }
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The program generates a compilation error.
(D) The number 2 gets printed with AssertionError
Answer : The program generates a compilation error.
Description :The condition in assert statement must be followed by a semi-colon.
Ques 18 : 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.
Answer : The class does not compile because the top level class cannot be protected.
Ques 19 : In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer.
public class test {
public static void main(String args[]) {
char c;
int i;
c = 'A'; // 1
i = c; //2
c = i + 1; //3
c++; //4
}
}
(A) The line labeled 1.
(B) The line labeled 2.
(C) The line labeled 3.
(D) All the lines are correct and the program compiles.
Answer : The line labeled 3.
Description :It is not possible to assign an integer to a character in this case without a cast.
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.
Answer : b, c, f, g