1.
Which of the following is the best-performing implementation of Set interface?
Correct Answer
A. HashSet
2.
Consider the following code snippet:
public class Welcome {
String title;
int value;
public Welcome() {
title += " Planet";
}
public void Welcome() {
System.out.println(title + " " + value);
}
public Welcome(int value) {
this.value = value;
title = "Welcome";
Welcome();
}
public static void main(String args[]) {
Welcome t = new Welcome(5);
}
}
Which of the following option will be the output for the above code snippet?
Correct Answer
C. Welcome 5
3.
Consider the following code:
class ExampleFive {
public static void main(String[] args) {
final int i = 22;
byte b = i;
System.out.println(i + ", " + b);
}
}
Which of the following gives the valid output for the above code?
Correct Answer
C. Prints: 22, 22
4.
Consider the following code snippet:
abstract class Director {
protected String name;
Director(String name) {
this.name = name;
}
abstract void occupation();
}
class FilmDirector extends Director {
FilmDirector(String name) {
super(name);
}
void occupation() {
System.out.println("Director " + name + " directs films");
}
}
public class TestDirector {
public static void main(String[] args) {
FilmDirector fd = new FilmDirector("Manirathnam");
fd.occupation();
new Director("Manirathnam") {
void occupation() {
System.out.println("Director " + name + " also produces films");
}
}.occupation();
}
}
Which of the following will be the output of the above code snippet?
Correct Answer
E. Prints: Director Manirathnam directs filmsDirector Manirathnam also produces films
5.
Consider the following code snippet:
class TestString2 {
public static void main(String args[]) {
String s1 = "Test1";
String s2 = "Test2";
s1.concat(s2);
System.out.println(""+s1.charAt(s1.length() - 3) + s1.indexOf(s2));
}
}
What will be the output of the above code snippet?
Correct Answer
B. S-1
6.
Consider the following code:
1. public class SwitchIt {
2. public static void main(String[] args) {
3. int w1 = 1;
4. int w2 = 2;
5. System.out.println(getW1W2(w1, w2));
6. }
7.
8. public static int getW1W2(int x, int y) {
9. switch (x) {
10. case 1: x = x + y;
11. case 2: x = x + y;
12. }
13. return x;
14. }
15. }
Which of the following gives the valid output of above code?
Correct Answer
A. Compilation succeeds and the program prints "5"
7.
Consider the following code snippet:
class Train {
String name = "Shatapdhi";
}
class TestTrain {
public static void main(String a[]) {
Train t = new Train();
System.out.println(t); // Line a
System.out.println(t.toString()); // Line b
}
}
Which of the following statements are true?(Choose 3)
Correct Answer(s)
A. Line a prints the corresponding classname with Object'shashcode in Hexadecimal
C. Both Line a and Line b will print the corresponding classnamewith Object's hashcode in Hexa Decimal
E. Output of Line a and Line b will be same
8.
Which of the following is true about finalize() method?
Correct Answer
A. The finalize() method is guaranteed to run once and onlyonce before the garbage collector deletes an object
9.
Consider the following program:
class RE {
public static void main(String args[]) {
try {
String s = null;
System.out.println(s.length());
}
catch(NullPointerException npe) {
System.out.println("NullPointerException handled");
throw new Exception(npe.getMessage());
}
}
}
What will be the output of the above program?
Correct Answer
C. Code does not complile
10.
Which of the following options will protect the underlying collections from
getting modified?
Correct Answer
A. UnmodifiableCollection(Collection
11.
Which of the following are correct regarding HashCode?(Choose 2)
Correct Answer(s)
B. It improves performance
C. It is a 32 bit numeric digest key
12.
Which of the following are true about inheritance?(Choose 3)
Correct Answer(s)
A. In an inheritance hierarchy, a subclass can also act as a superclass
B. Inheritance enables adding new features and functionality toan existing class without modifying the existing class
C. In an inheritance hierarchy, a superclass can also act as a subclass
13.
Consider the following program:
public class TryIt {
public static void main(String args[]) {
try {
int i = 0;
try {
i = 100 / i;
}
catch(Error e) {
System.out.println("Divide by Zero error");
}
System.out.println("Error Handled");
}
catch(Exception e) {
System.out.println("Unexpected exception caught");
}
}
}
What will be the output of the above program?
Correct Answer
D. Unexpected exception caught
14.
At which of the following given situations, unit tests are required to be run on
the modules?(Choose 3)
Correct Answer(s)
B. When the other methods, referred in a method in a moduleis modified
C. When class members are modified
D. When a method in a module is completed or modified
15.
Consider the following code:
1 public class A {
2 public void m1() {System.out.print("A.m1, ");}
3 protected void m2() {System.out.print("A.m2, ");}
4 private void m3() {System.out.print("A.m3, ");}
5 void m4() {System.out.print("A.m4, ");}
6
7 public static void main(String[] args) {
8
A a = new A();
9
a.m1();
10 a.m2();
11 a.m3();
12 a.m4();
13 }
14 }
Which of the following gives the lines that need to be removed in order to
compile and run the above code correctly?
Correct Answer
B. No need to comment any line. Will compile and run
16.
Which of the following options give the names of data structures that can be
used for elements that have ordering, but no duplicates? (Choose 2)
Correct Answer(s)
C. TreeSet
E. SortedSet
17.
Which of the following class in java.sql package maps the SQL data types to Java
datatypes?
Correct Answer
C. Types
18.
Which of the following options gives the difference between == operator and
equals() method?
Correct Answer
D. ==compares object's memory address but equals charactersequence
19.
Consider the following code:
package test;
class Target {
String name = "hello";
}
Which of the following options are valid that can directly access and change the
value of the variable 'name' in the above code? (Choose 2)
Correct Answer(s)
B. Any class that extends Target within the test package
E. Any class in the test package
20.
Which of the following are the valid ways of conversion from Wrapper type to
primitive type? (Choose 3)
Correct Answer(s)
B. New Double(24.5d).byteValue();
D. New Float(100).intValue();
E. New Integer(100).intValue();
21.
Which of the following classes is new to JDK 1.6?
Correct Answer
D. Java.io.Console
22.
Which of the following statements are correct regarding Static Blocks?(Choose
3)
Correct Answer(s)
B. A class can have more than one static block
C. Static blocks are executed only once
D. Static blocks are executed before main() method
23.
Which of the following ways can be used to access the String value in the first
column of a ResultSet? (Assume rs is the ResultSet object)
Correct Answer
A. Rs.getString(1);
24.
Which of the following options gives the relationship between a Spreadsheet
Object and Cell Objects?
Correct Answer
C. Aggregation
25.
Consider the following program:
class A implements Runnable {
public void run() {
System.out.print(Thread.currentThread().getName());
}
}
class B implements Runnable {
public void run() {
new A().run();
new Thread(new A(),"T2").run();
new Thread(new A(),"T3").start();
}
}
class C {
public static void main (String[] args) {
new Thread(new B(),"T1").start();
}
}
What will be the output of the above program?
Correct Answer
E. Prints: T1T1T3
26.
Consider the following program:
public class Exp4 {
static String s = "smile!..";
public static void main(String[] args) {
new Exp4().s1();
System.out.println(s);
}
void s1() {
try {
s2();
}
catch (Exception e) {
s += "morning";
}
}
void s2() throws Exception {
s3();
s += "evening";
s3();
s += "good";
}
void s3() throws Exception {
throw new Exception();
}
}
What will be the output of the above program?
Correct Answer
C. Smile!..morning
27.
A monitor called 'mon' has 5 threads in its waiting pool; all these waiting
threads have the same priority. One of the threads is thread1. How can you
notify thread1 so that it alone moves from Waiting state to Ready State?
Correct Answer
E. You cannot specify which thread will get notified
28.
Consider the following scenario:
Here is part of the hierarchy of exceptions that may be thrown during file IO
operations:
Exception
+-IOException
+-File Not Found Exception
You have a method X that is supposed to open a file by name and read data
from it.
Given that X does not have any try-catch statements, which of the following
option is true?
Correct Answer
C. The method X must be declared as throwing IOException orException
29.
The return value of execute() method in Statement interface is
__________________.
Correct Answer
B. Boolean
30.
Consider the following program:
public class D extends Thread {
public void run() {
System.out.println("Before start method");
this.stop();
System.out.println("After stop method");
}
public static void main(String[] args) {
D a = new D();
a.start();
}
}
What will be the output of the above program?
Correct Answer
C. 'Before start method' only
31.
Consider the following code:
public class Choco {
Choco() { System.out.print("Choco"); }
class Bar {
Bar() { System.out.print("bar"); }
public void go() { System.out.print("sweet"); }
}
public static void main(String[] args) {
Choco c = new Choco();
c.makeBar();
}
void makeBar(){
// Insert code here
}
}
Which of the following code snippet when substituted individually to the above
commented line (// Insert code here) will give the following output?
Chocobarsweet
Correct Answer
D. (new Bar() {}).go();
32.
Which of the following actions include the external library required by Java
application at runtime in order to run properly? (choose 2)
Correct Answer(s)
B. Adding the folder name or jar filename to the CLASSPATHvariable, where the class files of the library exists
C. Running the application with the following switchesjava -cp ApplicationClassNamejava -classpath ApplicationClassName
33.
You need to create a class that implements the Runnable interface to do
background image processing. Out of the following list of method declarations,
select the method that must satisfy the requirements.
Correct Answer
B. Public void run()
34.
Which of the following gives the set of Annotations declared in java.lang
package?
Correct Answer
B. @Deprecated, @Override, @SuppressWarning
35.
Consider the following code:
class ABC {
public void method1() {
DEF def = new DEF();
def.method2();
}
}
class DEF {
public XYZ xyz;
public String method2() {
return xyz.method3();
}
}
class XYZ {
public String value;
public String method3() {
value = "XYZ";
return value;
}
}
class TestCode {
public static void main(String args[]) {
ABC abc = new ABC();
abc.method1();
}
}
Which of the following will be the output if the above code is compiled and
executed?
Correct Answer
A. An exception is thrown at runtime
36.
To which of the following elements, annotations can be applied? (Choose 3)
Correct Answer(s)
A. Fields
C. Classes
D. Methods
37.
Consider the following scenario:
A Java application needs to stream a video from a movie file.
Which of the following options gives the correct combination of stream classes
that can be used to implement the above requirement?
Correct Answer
E. FileInputStream and BufferedInputStream
38.
Consider the following code:
public class SwitchIt {
public static void main(String args[]) {
int x = 10;
switch(x) {
case 10:
for(int i=0; i
break;
case 20:
System.out.println(x);
break;
case 30:
System.out.println(x*2);
break;
default:
System.out.println(x*3);
}
}
}
Which of the following will be the output for the above program?
Correct Answer
B. 10
39.
Consider the following code:
class A { }
class B extends A { }
public class Code2 {
public void method(A a) {
System.out.println("A");
}
public void method(B b) {
System.out.println("B");
}
public static void main(String args[]) {
new Code2().method(new Object());
}
}
Which of the following will be the output for the above code?
Correct Answer
C. Compilation Error 'Cannot find the symbol'
40.
Consider the following code snippet:
class Lock1 {
Lock1() { }
Lock1(Lock2 lock2) { this.lock2 = lock2; }
Lock2 lock2;
}
class Lock2 {
Lock2() { }
Lock2(Lock1 lock1) { this.lock1 = lock1; }
Lock1 lock1;
}
class GC6 {
public static void main(String args[]) {
Lock1 l1 = new Lock1();
Lock2 l2 = new Lock2(l1);
l1.lock2 = l2;
}
}
Which of the objects are eligible for garbage collection in the above code?
Correct Answer(s)
D. L1
E. L2
41.
Consider the following code snippet:
import java.io.*;
class Student {
private String studentID;
private String studentName;
public Student() { }
public Student(String studentID, String studentName) {
this.studentID = studentID;
this.studentName = studentName;
}
public String toString() {
return "Student ID : " + studentID + " " +
"Student Name : " + studentName;
}
}
public class IOCode3 {
public static void main(String args[]) throws FileNotFoundException,
IOException {
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream("C:/ObjectData")); // Line 1
out.writeObject(new Student("100", "Student One")); // Line 2
out.close();
}
}
What will be the output of the above code snippet?
Correct Answer
D. Throws NotSerializableException at // Line 2
42.
Consider the following code snippet:
interface i1 {
int i = 0;
}
interface i2 {
int i = 0;
}
class inter implements i1, i2 {
public static void main(String[] a) {
System.out.println(i);
}
}
Which of the following options will be the output of the above code snippet?
Correct Answer
D. Compilation Error
43.
Consider the following code:
1. class ExampleSix {
2. String msg = "Type is ";
3. public void showType(int n) {
4. String tmp;
5. if(n > 0) tmp = "positive";
6. System.out.println(msg + tmp);
7. }
8. }
On running the above code it throws the compile-time error- the variable tmp is
not initialised.
Which of the following changes to the above code will make the code to
compile properly? (Choose 3)
Correct Answer(s)
C. Insert the following line at line 6else tmp = "not positive";
D. Change line 4 as followsString tmp = null;
E. Remove line 4 and insert it at line 2
44.
Consider the following code:
class One {
public One() {
System.out.print(1);
}
}
class Two extends One {
public Two() {
System.out.print(2);
}
}
class Three extends Two {
public Three() {
System.out.print(3);
}
}
public class Numbers {
public static void main(String[] argv) {
new Three();
}
}
Which of the following will be the output for the above program?
Correct Answer
B. 123
45.
Consider the following code snippet:
class Student {
String studentID;
String studentName;
double score;
}
The instances of the above defined class holds the information of individual
student. These details needs to be maintained in a data structure, that
* allows searching of student details using studentID
* ascending order of Student objects based on studentID
Which of the following collection classes can be used to implement the above
scenario?
Correct Answer
E. TreeMap