J 2
J 2
J 2
a) Abstract
b) Non-abstract
c) Implemented
d) Unimplemented
Ans: c
2) Which of the following methods cause the String object referenced by s to be changed?
a) s.concat( )
b) s.toUpperCase( )
c) both a) & b)
d) none
Ans : c
4) Assuming a method contains code which may raise an Exception (but not a
RuntimeException), what is the correct way for a method to indicate that it expects the
caller to handle that exception?
a) throw Exception
b) throws Exception
c) new Exception
d) Don't need to specify anything
Answer : b
6) What is the name of the interface that can be used to define a class that can execute
within its own thread?
a) Run
b) Runnable
c) Thread
d) Executable
Answer : b
ANSWER : b) defabc
Answer : b
9) Carefully examine the following code, When will the string "Hi there" be printed?
public class StaticTest {
static {
System.out.println("Hi there");
}
public void print() {
System.out.println("Hello");
}
public static void main(String args []) {
StaticTest st1 = new StaticTest();
st1.print();
StaticTest st2 = new StaticTest();
st2.print();
}
}
a) Never.
b) Each time a new instance is created.
c) Once when the class is first loaded into the Java virtual machine.
d) Only when the static method is called explicitly.
Answer : c
10) What changes are needed to make the following program to compile?
import java.util.*;
class Ques{
public static void main (String args[]) {
String s1 = "abc";
String s2 = "def";
Vector v = new Vector();
v.add(s1);
v.add(s2);
String s3 = v.elementAt(0) + v.elementAt(1);
System.out.println(s3);
}
}
Answer : c
13) Given that a Button can generate an ActionEvent which listener would you expect to
have to implement, in a class which would handle this event?
a) FocusListener
b) EventListener
c) ButtonListener
d) ActionListener
Answer : d
14) In Java, an abstract class cannot be sub-classed.
A. True B. False
Answer:
15) What is the result of evaluating the expression 14 ^ 23. Select the one correct answer.
A) 25 B) 37 C) 6 D) 31
Answer: