Java CTS Dumps 3
Java CTS Dumps 3
Java CTS Dumps 3
interface Greek { }
b. Alpha a = x;
c. Greek f = (Alpha)x;
d. Beta b = (Beta)(Alpha)x;
e. Greek f = (Delta)x;
class Node {
Node node;
}
class NodeChain {
public static void main(String a[]) {
Node node1 = new Node(); // Line 1
node1.node = node1;
// Code here
}
}
Which of the following code snippets when replaced at the comment line (//
Code Here) in the above code will make the object created at Line 1, eligible for
garbage collection? (Choose 2)
b. node1 = null;
c. node1.node = null;
d. node1 = node1.node;
class Component {
private int param;
public void setParam(int param) { this.param = param; }
public int getParam() { return param; }
}
class Container {
private Component component;
public void setComponent(Component component) { this.component =
component; }
public Component getComponent() { return component; }
}
int j = 10;
component.setParam(j);
container.setComponent(component);
c. component.setParam(100);
e. container.getComponent().setParam(100);
5 Consider the following code:
b. Prints 2, false
c. Prints: 1, false
d. Prints: 2, true
d. Planet
e. Planet Welcome
class C {
public static void main (String[] args) {
new Thread(new B(),"T1").start();
}
}
b. Prints: T1T2T3
c. Prints: T1T1T2
d. Prints: T1T1T3
e. Prints: T1T1T1
Answer: a. NavigableSet
b. Deque
c. NavigableMap
d. NavigableList
b. Serializable interface
c. Readable interface
d. Externalizable interface
e. Writable interface
10 Consider the following code:
Which of the following implementations use the Shape class correctly? (Choose
2)
12 Which of the following flow control features does Java support? (Choose 2)
b. Labeled goto
c. Labeled throw
d. Labeled catch
e. Labeled break
class Resource { }
class UserThread extends Thread {
public Resource res;
public void run() {
try {
synchronized(res) {
System.out.println("Planet");
res.wait();
Thread.sleep(1000);
res.notify();
System.out.println("Earth");
}
} catch(InterruptedException e) { }
}
}
Which of the following will give the correct output for the above code?
c. Compile-time Error
class Alpha {
protected Beta b;
}
class Beta { }
You are writing a set of classes related to cooking and have created your own
exception hierarchy derived from java.lang.Exception as follows:
Exception
+-Bad TasteException
+-Bitter Exception
+-Sour Excpetion
Which of the following method calls would refer to the letter b in the string
referred by the variable deepak?
Answer: a. charAt(13)
b. charAt(15)
c. charAt(12)
d. charAt(16)
e. charAt(14)
import java.io.*;
Answer: a. Reads the text from keyboard and prints the same to the
console on pressing Ctrl Z, flushes (erases) the same from the
console.
c. Reads the text from keyboard line by line and prints the same
to the console on pressing ENTER key at the end of every line
d. Reads the text from keyboard line by line and prints the same
to the console on pressing ENTER key at the end of every line,
then the same is flushed (erased) from the console.
e. Reads the text from keyboard and prints the same to the
console on pressing Ctrl Z
20 Which of the following options gives the relationship between a Pilot class and
Plane class?
Answer: a. Inheritance
b. Polymorphism
c. Persistence
d. Aggregation
e. Association
import java.util.*;
import java.text.*;
Which of the following code snippets, when substituted to (//Insert Code here)
in the above program, will convert the dob from String to Date type?
Date d = g.getDate();
e. CalendarFormat cf = new
SimpleCalendarFormat("dd/MM/yyyy");
try {
Date d = cf.parse(dob);
} catch(ParseException pe) { }
Answer: a. welcome
class two
c. class two
e. two
24 Consider the following code:
Which of the following gives the valid output for the above code?
c. Prints: equals
d. Prints: EQ
e. Prints: equals EQ
class TestString3 {
public static void main(String args[]) {
String s1 = "Hello";
StringBuffer sb = new StringBuffer(s1);
sb.reverse();
s1.concat(sb.toString());
Answer: a. HelloolleH55
b. HelloolleH44
c. HelloHello44
d. HelloHello33
e. HelloHello55
return rslt;
}
b. Runtime Error
c. NO
d. false
e. true
Answer: a. toString()
b. compareTo(Object)
c. hashCode()
d. equals(Object)
e. run()
29 Consider the following code:
Which of the following will be the output for the above code?
b. 1000
public Welcome() {
title += " Planet";
}
Which of the following option will be the output for the above code snippet?
c. Compilation fails
d. Welcome 5
e. Welcome Planet 5
Which of the following gives the correct output for the above code?
Answer: a. Prints: 21 21
b. Prints: 20 21
d. Prints: 20 20
e. Prints: 21 20
import java.util.*;
Which of the following code snippets when replaced at the line marked //Line 1,
will make the ArrayList a to accept only Wrapper types of primitive numerics?
36 The following class definitions are in separate files. Note that the Widget and
BigWidget classes are in different packages:
1. package conglomo;
2. public class Widget extends Object{
3. private int myWidth;
4. XXXXXX void setWidth( int n ) {
5. myWidth = n;
6. }
7. }
Which of the following modifiers, used in line 4 instead of XXXXXX, would allow
the BigWidget class to access the setWidth method (as in line 12)? (Choose 2)
Answer: a. default (blank), that is, the method declaration would read
void setWidth( int n )
b. final
c. private
d. protected
e. public
Which of the following options gives the exact meaning of the method call
s1.retainAll(s2)?
b. runtime error
c. Catchable caught
null pointer exception
null pointer exception
d. compile-time error
Answer: a. To call the join() method, a thread must own the lock of the
object on which the call is to be made
b. To call the yield() method, a thread must own the lock of the
object on which the call is to be made.
c. To call the wait() method, a thread must own the lock of the
object on which the call is to be made.
d. To call the wait() method, a thread must own the lock of the
current thread.
e. To call the sleep() method, a thread must own the lock of the
object which the call is to be made.
Answer: a. last()
b. hasRecords()
c. previous()
d. next()
e. first()
42 Which of the following are true about SQLWarning class in JDBC API?
@interface Author {
String name();
String date();
}
Which of the following is the correct way of implementing the above declared
annotation type?
Answer: a. Author(
name = "Deepak",
date = "02/04/2008"
)
class MyClass() { }
b. @Author(
name = "Deepak",
)
class MyClass() { }
c. @Author(
"Deepak",
"02/04/2008"
)
class MyClass() { }
e. @Author(
name = "Deepak",
date = "02/04/2008"
)
class MyClass() { }
// Code here
System.out.println("match");
} else {
System.out.println("no match");
}
}
}
Which of the following code snippet when substituted at the commented line
(// Code here) in the above code will make the program to print "no match"?
Answer: a. if (x != y[0].toString()) {
b. if (x & y[0]) {
c. if (x.equals(y[0])) {
d. if (!x.equals(y[0])) {