Sunteți pe pagina 1din 5

1) An Interface contains___________ methods

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

3) Which of the following statements are true?


a) UTF characters are all 8-bits.
b) UTF characters are all 16-bits.
c) Bytecode characters are all 16-bits.
d) Unicode characters are all 16-bits.
Ans : d.

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

5) What is the correct declaration of an abstract method that is intended to be public?


a) public abstract void add();
b) public abstract void add() {}
c) public abstract add();
d) public void add();
Answer : a

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

7) What is the output of the program?


import java.util.*;
class Ques
{
public static void main (String args[])
{
String s1 = "abc";
String s2 = "def";
Stack stack = new Stack();
stack.push(s1);
stack.push(s2);
try
{
String s3 = (String) stack.pop() + (String) stack.pop() ;
System.out.println(s3);
}
catch (EmptyStackException ex){}
}
}

a) abcdef b) defabc c) abcabc d) defdef

ANSWER : b) defabc

8) Carefully examine the following class:

public class CHead {


public static void main (String args []) {
/* This is the start of a comment
if (true) {
CHead = new chead();
System.out.println("Done the test");
}
/* This is another comment */
System.out.println ("The end");
}
}

a) Prints out "Done the test" and nothing else.


b) The program prints out "The end" and nothing else.
c) The program prints out both "Done the test" and "The end".
d) The program produces no output but terminates correctly.

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);
}
}

A) Declare Ques as public


B) Cast v.elementAt(0) to a String
C) Cast v.elementAt(1) to an Object
D) Import java.lang

ANSWER : B) Cast v.elementAt(0) to a String

11) Examine the following class definition:


public class Test {
public static void test() {
print();
}
public static void print() {
System.out.println("Test");
}
public void print() {
System.out.println("Another Test");
}
}

What is the result of compiling this class?


a) A successful compilation.
b) A warning stating that the class has no main method.
c) An error stating that there is a duplicated method.
d) An error stating that the method test() will call one or other of the print() methods.

Answer : c

12) Given the following code what is the effect of a being 5:


public class Test {
public void add(int a) {
loop: for (int i = 1; i < 3; i++){
for (int j = 1; j < 3; j++) {
if (a == 5) {
break loop;
}
System.out.println(i * j);
}}}}
a) Generate a runtime error
b) Throw an ArrayIndexOutOfBoundsException
c) Print the values: 1, 2, 2, 4
d) Complies and runs without producing an output
Answer : a

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:

S-ar putea să vă placă și