Java CTS Dumps 2
Java CTS Dumps 2
Java CTS Dumps 2
Answer: a. HashSet
b. TreeSet
c. Hashtable
d. LinkedHashSet
e. SortedSet
public Welcome() {
title += " Planet";
}
Which of the following option will be the output for the above code snippet?
Answer: a. Compilation fails
b. Welcome Planet 5
c. Welcome 5
d. Welcome Planet
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?
c. Prints: 22, 22
Director(String name) {
this.name = name;
}
abstract void occupation();
}
void occupation() {
System.out.println("Director " + name + " directs films");
}
}
Which of the following will be the output of the above code snippet?
d. Runtime Error
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));
}
}
Answer: a. s5
b. s-1
c. t4
d. 15
e. T4
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
}
}
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());
}
}
}
10 Which of the following options will protect the underlying collections from
getting modified?
b. Collections.checked
c. synchronizedCollection(Collection<T> c);
b. It improves performance
e. Error Handled
Unexpected exception caught
14 At which of the following given situations, unit tests are required to be run on
the modules?(Choose 3)
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?
d. Line 11
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)
Answer: a. ArrayList
b. List
c. TreeSet
d. Set
e. SortedSet
17 Which of the following class in java.sql package maps the SQL data types to Java
datatypes?
b. JDBCTypes
c. Types
d. JDBCSQLTypes
e. SQLTypes
18 Which of the following options gives the difference between == operator and
equals() method?
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)
b. new Double(24.5d).byteValue();
c. new Integer(1).booleanValue();
d. new Float(100).intValue();
e. new Integer(100).intValue();
Answer: a. java.io.File
b. java.io.Serializable
c. java.io.FileFilter
d. java.io.Console
e. java.io.Externalizable
Answer: a. A class that have static block, should have the main() method
defined in it
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)
Answer: a. rs.getString(1);
b. rs.getString("one");
d. rs.getString("first");
e. rs.getString(0);
Answer: a. Polymorphism
b. Association
c. Aggregation
d. Inheritance
e. Persistence
class C {
public static void main (String[] args) {
new Thread(new B(),"T1").start();
}
}
b. Prints: T1T2T3
c. Prints: T1T1T2
d. Prints: T1T1T1
e. Prints: T1T1T3
void s1() {
try {
s2();
}
catch (Exception e) {
s += "morning";
}
}
Answer: a. smile!..eveningmorning
b. smile!..morningevening
c. smile!..morning
d. smile!..morningeveninggood
e. smile!..
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?
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?
c. ResultSet
d. array of ResultSet
e. int value
b. Compilation error
d. Runtime exception
Which of the following code snippet when substituted individually to the above
commented line (// Insert code here) will give the following output?
Chocobarsweet
b. new Bar().go();
e. go();
32 Which of the following actions include the external library required by Java
application at runtime in order to run properly? (choose 2)
Answer: a. Compressing the class into zip files and converting it into
executable modules, and then packaging it into a jar file
c. @Comment, @Class
d. @Documented, @Inherited
class DEF {
public XYZ xyz;
class XYZ {
public String 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?
b. Prints: XYZ
c. Compilation fails
d. Prints: DEF
e. Prints: ABC
Answer: a. fields
b. jar files
c. classes
d. methods
e. class files
Which of the following options gives the correct combination of stream classes
that can be used to implement the above requirement?
switch(x) {
case 10:
for(int i=0; i<x; ++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?
Answer: a. 10
b. 11
c. No output
d. 30
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?
Answer: a. Prints: B
d. Prints: A
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?
Answer: a. l1
b. l2
d. lock1
e. lock2
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;
}
interface i1 {
int i = 0;
}
interface i2 {
int i = 0;
}
Which of the following options will be the output of the above code snippet?
Answer: a. No output
b. Prints: 0
c. Runtime Error
d. Compilation Error
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)
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?
Answer: a. 321
b. No output
c. 123
d. 32
e. 3
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
Which of the following collection classes can be used to implement the above
scenario?
Answer: a. TreeSet
b. HashMap
c. HashSet
d. ArrayList
e. TreeMap