Java CTS Dumps 4
Java CTS Dumps 4
(Choose 3)
b. StringBuffer is threadsafe
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 changes made to the above code will make the code to
compile and execute properly and gives the following output?
String1
String2
Which of the following options gives the exact meaning of the method call
s1.retainAll(s2)?
A Chat application written in Java, currently works with a general room facility,
where the messages posted by the logged user are displayed. A common
synchronized object is ued to Queue up the messages received from the users.
Now, the application needs additional feature called personal messaging, that
enables the user to make one-to-one communication.
Answer: a. To call the sleep() method, a thread must own the lock of the
object which the call is to be made.
b. To call the join() 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 yield() method, a thread must own the lock of the
object on which the call is to be made.
e. To call the wait() method, a thread must own the lock of the
current thread.
class Animal {
public String noise() { return "noise"; }
}
Which of the following option will be the output of the above code snippet?
Answer: a. noise
b. bark
c. meow
d. Compilation fails
b. invt = grts;
Which of the following will be the output for the above program?
Answer: a. 10
10
20
b. 10
20
c. 10
10
d. Compilation Error
e. 30
14 Which of the following is the process of creating a new class from an existing
class?
Answer: a. Polymorphism
b. Abstraction
c. Inheritance
d. Reusability
Which of the following options will give the output for the method call
deepak.charAt(10)?
b. s
c. h
d. space
package com.java.test;
public class A {
public void m1() {System.out.print("A.m1, ");}
protected void m2() {System.out.print("A.m2, ");}
private void m3() {System.out.print("A.m3, ");}
void m4() {System.out.print("A.m4, ");}
}
class B {
public static void main(String[] args) {
A a = new A();
a.m1(); // 1
a.m2(); // 2
a.m3(); // 3
a.m4(); // 4
}
}
Assume that both of the above classes are stored in a single source file called
'A.java'. Which of the following gives the valid output of the above code?
b. Compile-time error at 3.
c. Compile-time error at 4.
d. Compile-time error at 2.
e. Compile-time error at 1.
Which of the following options provide the valid code to accomplish the above
given scenario?
c. new LinkedTreeSet<Type>(c);
d. new LinkedHashSet<Type>(c);
Answer: a. NavigableSet
b. NavigableList
c. NavigableMap
d. Deque
Answer: a. public
b. final
c. abstract
d. private
e. protected
b. @interface author{
@String name();
@String date();
}
c. interface author{
String name(),
String date()
}
d. interface @author{
String name(),
String date()
}
e. @interface author{
String name();
String date();
}
22 Consider the following code:
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?
b. Compile-time Error
Answer: a. Polymorphism
b. Association
c. Inheritance
d. Aggregation
e. Persistence
b. welcome
class two
c. two
e. class two
Which of the following option will be the output for the above code snippet?
Answer: a. one
two
b. two
one
Which of the following options will be the output for the above code snippet?
Answer: a. Welcome
b. Welcome Planet
c. Compilation fails
e. Welcome Planet 5
Which of the following options are true regarding the output of the above
program? (Choose 2)
Answer: a. If run with no arguments, the program will print "The end"
b. If run with one argument, the program will print the given
argument followed by "The end"
c. If run with one argument, the program will simply print the
given argument
class GC2 {
public GC2 getIt(GC2 gc2) {
return gc2;
}
c = g.getIt(c);
}
}
How many objects are eligible for Garbage Collection?
Answer: a. four
b. one
d. two
e. three
A given String needs to be searched, in text file, and report the number of
occurences with corresponding line numbers.
Which of the following stream classes can be used to implement the above
requirement?
and given that another part of the class has the following code
Which of the following will be the output for the statement in line 9?
b. Created Program
c. Created Program.java
d. Created Program.java.txt
import java.io.*;
Answer: a. 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.
b. 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
c. Reads the text from keyboard and prints the same to the
console on pressing Ctrl Z, flushes (erases) the same from the
console.
d. Reads the text from keyboard and prints the same to the
console on pressing Ctrl Z
Which of the following gives the valid output for the above code?
b. Prints: EQ
d. Prints: equals EQ
e. Prints: equals
34 Consider a List based object L, with size of 10 elements e, and the following two
lines of code:
L.add("e");
L.remove("e");
Which of the following options gives the status about the List object L after
executing the above two lines of code?
Answer: a. New elements are added and old ones are taken out but size
is increasing
b. New elements are added and old ones are taken out but
there will be a change in size
d. New elements are added and old ones are taken out but no
change in size
class A {
public void method(Object object) {
System.out.println("Object");
}
public void method(String string) {
System.out.println("String");
}
public static void main(String args[]) {
new A().method(null);
}
}
Which of the following options will be the output for the above code?
b. Prints: String
d. Prints: Object
class MyClass {
int myValue;
@Override
public boolean equals(Object o1, Object o2){
MyClass mc1=(MyClass) o1;
MyClass mc1=(MyClass) o2;
if(mc1.myValue==mc2.myValue)
return true;
return false;
}
}
import java.io.*;
Which of the following when substituted in place of commented lines (// Line 1,
Line 2 and Line 3) produce the desired output?
Which of the followingl gives the correct valid output for the above code?
b. king queen
c. Compilation fails.
d. MyThread king
e. MyThread queen
Answer: a. SQLWarning
b. Statement
c. Connection
d. DriverManager
e. CallableStatement
40 Consider the following code:
Which of the following code snippet when substituted individually to the above
commented line (// Insert code here) will give the following output?
Chocobarsweet
Answer: a. go();
d. new Bar().go();
e. new Choco().go();
b. Welcome Planet
c. Planet Welcome
d. Planet
e. Compilation Error
1. class Test {
2. public static void main(String args[]) {
3. double d = 12.3;
4. Dec dec = new Dec();
5. dec.dec(d);
6. System.out.println(d);
7. }
8. }
9. class Dec{
10. public void dec(double d) { d = d - 2.0d; }
11. }
c. Prints: 12.3
d. Prints: 0.0
43 All kinds of looping constructs designed using while loop can also be
constructed using do-while loop.
State True or False.
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?
Answer: a. DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try {
Date d = df.parse(dob);
} catch(ParseException pe) { }
Date d = g.getDate();
d. CalendarFormat cf = new
SimpleCalendarFormat("dd/MM/yyyy");
try {
Date d = cf.parse(dob);
} catch(ParseException pe) { }