Você está na página 1de 19

1. What of the following will stop the execution of a running Thread ?

A. When the thread throws an interrupted exception.


B. When a high priority thread starts running.
C. While the thread’s wait method is called.
D. When the main method completes.
E. In the running thread when a new thread is created
 

 
 
 

2. Which of the following will throw a NullPointerException?

String s = null;

A. if ((s!=null) & (s.length() > 0))


B. if ((s!=null) && (s.length() == 0))
C. if ((s==null) | (s.length() > 0))
D. if ((s==null) || (s.length() > 0))
 

 
 
 

3. Which of the following describes a fully encapsulated class?


A. Methods cannot be private
B. Variables cannot be private
C. All instance variables are private.
D. All instance variables are public
E. All instance variables are private and public accessor methods
are provided to get the values of instance variables
 

 
 
 

4. In the following program, if somecondition() returns true, then only line


number 3 must throw a custom exception MyException. MyException is
not a subclass of runtime exceptions. What are the changes to be made to
the given method to handle the eception

1. Class Exceptionthrown{
2. public void method() {
3. --------------
4. ---------------
5. If (somecondition()) {
6. }
7. }
8. }
 

 
 
 

A. Add throws new MyException(); in line number 4


B. Add throw MyException(); in line number 6
C. Add throw new MyException(); in line number 6
D. Add throw new MyException(); in line number 4
E. Modify the method declaration such that an object of type
Exception is to be thrown
 

 
 
 

2. What is the output of the following program

public class Trial{

int x;

public static void main(String args[]) {

x = 8;

System.out.print("The value of x is " + x);

}}

A. The program prints The value of x is 8;


B. The program prints The value of x is 0;
C. The program will not compile.
 

 
 
 
3. Given the following code
 

Float F1 = new Float(0.9F);

Float F2 = new Float(0.9F);

Double D1 = new Double (0.9);

Which of the following will return true?

A. (F1 == F2)
B. (F1 == D2)
C. F1.equals(F2)
D. F1.equals(D2)
E. F1.equals(new Float(0.9F))
 

 
 
 

4. What are the assignments which are valid in the line XXXX
 

class Super{

private int i;

public int ma_cd(float f){

i = (int) f;

return i;

class Sub extends Super{

int j;
float g;

public Sub(){

Super s = new Super();

XXXX

A. j = i;
B. g = f;
C. j = s.ma_cd(3.2f);
D. j = s.i;
E. g = s.f;
 

 
 
 

5. Which is the earliest possible instance at which the String object referred
by s is eligible for Garbage Collection?

public static void main(String args[ ]){

1. String s = "abcd";
2. String s1 = "efghi";
3. String s2 = s+ s1;
4. s = null;
5. s = s1;
6. s1 = s;
 

 
 
 

A. Before Line 4.
B. Before Line 5 starts
C. After Line 5.
D. Before line 6.
 
 
 
 

2. A Polygon is drawable. You want to store the coordinates of the Polygon


in a vector. The Polygon has color and fill flags. Which of the following
types will you choose for declaring the variables of a Polygon class.
A. Vector
B. drawable
C. Polygon
D. Color
E. Boolean
 

 
 
 

3. An Employee is a Person. The Employee has a identity, name etc. There


is a plan to prepare a class of type Employee which is going to used in
many unrelated parts of the project. Using the following keywords
construct a class that defines an Employee.
 

abstract, public, Employee, throws, class, Person, void, extends

public class Employee extends Person

4. FilterOutputStream has sub classes such as BufferedOutputStream,


DataOutputStream and PrintStream. Which of the following is the valid
argument type for the constructor of the FilterOutputStream
A. File
B. PrintStream
C. DataOutputStream
D. BufferedOutputstream
E. FileOutputStream
 

 
 
 
5. What is the equivalent Octal representation of 7 (not more that 4
characters)
 

07

6. What is the return type of the methods in Java 2 Listener Interfaces ?


A. Boolean
B. boolean
C. void
D. String
E. int
 

 
 
 

7. Which of the following is true regarding GridBagLayout


A. if a component has been given fill both is true, then as the
container resizes the component resizes
B. The number of rows and columns are fixed while loading the
components.
C. The number of rows and columns are fixed while loading the layout
itself .
D. if a component has a non-zero weightY value, then the component
grows in height as the container is resized.
 

 
 
 

8. Given the following code

switch(x){

case 1: System.out.println("Test 1");

case 2:

case 3: System.out.println("Test 3");

break;
default : System.out.println("Test 4");

break;

What are the possible values of x if "Test 3" is to be printed ?

A. 4
B. 2
C. 3
D. 1
E. 0
 

 
 
 

9. What is the valid argument type for the methods in a MouseMotionListener


Interface ?
 

MouseEvent

10. Which of the following is valid native method declaration in Java ?

a. public static void native method1(){}


b. static void native method1(){}
c. static native void method1();
d. static void native method1(){}
e. static native int method1();
 

 
 
 

2. Given the following code

class Super{

public void method1() {}


}

class Sub extends Super{

// xx

Which of the following methods can be legally added at line marked


xx ?

a. int method1() { }
b. String method1() throws IOException{ }
c. void method1(String s) { }
d. void method1(Float s) { }
e. public void method2() { }
 

 
 
 

3. Given the following code


 

if (x > 4) {

System.out.println( "Test 1" );

else if (x> 9){

System.out.println("Test 2");

else

System.out.println("Test 3");

What are the possible values of x that will cause "Test 2 " to be printed ?

A. 0 to 4
B. Less than 0
C. 5 to 9
D. 10 and greater
E. None
 

 
 
 

2. What is the range of a char type?


 

0 to 216-1

3. Which of the following are true about >> and >>> operators?
A. >> performs a unsigned shift and >>> performs a rotate.
B. >> performs a signed shift and >>> performs an unsigned
shift.
C. >> performs an unsigned shift and >>> performs a signed shift.
 

 
 
 

4. What are valid Java keywords


A. NULL
B. null
C. TRUE
D. implements
E. interface
F. instanceof
G. sizeof
 

 
 
 

5. Which of the following collection objects can be used for storing values
that may appear more than once and ordered ?
A. Map
B. List //dupes + ordered
C. Set
D. Collection // dupes + unordered
 

 
 
 

6. You want a component to retain its width, but not the height when resized.
How will you achieve this ?
A. Place the component in North or South in a BorderLayout
B. Place the component in the Center of a BorderLayout
C. Place the component in East or West in a BorderLayout
 

 
 
 

7. You have defined a class and sub classes of the same. But you don’t want
the methods of the super class to be overridden . what modifier you will
use for declaring the methods of the super class ?
 

final

8. What is the body of is a body code of a Thread


A. public void run()
B. public void start()
C. public void runnable()
D. public static void main(String args[])
 

 
 
 

9. What is the output of the following code?

int i = 0;

while(i-- > 0) {

System.out.println("The value of i is " + i);


}

System.out.println("Finished");

A. The value of i is 1
B. The value of i is 0
C. Finished
D. Compilation Error
E. Runtime Error
 

 
 
 

10. What is the output of the following program

class Example{

static int arr[] = new int[10];

public static void main(String args[]){

System.out.println(" The value 4th element is " + arr[4]);

A. The value of 4th element is 4


B. The value of 4th element is null
C. The value of 4th element is 0
D. Null Pointer exception is raised
E. Runtime error, because the class is not instantiated
 

 
 
 

11. Which of the following is the correct class declaration for Car.java. See to
that it is a case-sensitive system
A. public class Car{
 

 
int in;

public Car(int inn){

in = inn

B. public class Car extends Truck, Vehicle{


 

int in;

public Car(int inn){

in = inn;

C. public class Car{


 

int in;

public abstract void raceCar() {System.out.println("RaceCar");}

public Car(int inn){

in = inn;

D. public class Car{


 
 
 
 

12. int in;


13. public Car(int inn){

14. in = inn;

15. } }

16. Which of the following is true about Garbage Collection mechanism


A. Garbage Collection is carried out at predictable intervals
B. The programmer can write come complex code to perform garbage
collection
C. The programmer can make objects eligible for garbage
collection through the reference variables
D. Garbage collection cannot be performed on objects which are
referred by the running threads.
 

 
 
 

17. What is the output of the following program?


 

class Super{

String name;

Super(String s){

name =s ;

}}

class Sub extends Super{

String name;

Sub(String s){
name=s;

public static void main(String args[]){

Super sup = new Super("First");

Sub sub = new Sub("Second");

System.out.println(sub.name + " " + sup.name);

}}

A. First Second
B. Second First
C. Compilation error
D. Runtime error stating same name found in Super as well as in the
Sub class
 

 
 
 

18. java.awt.AWTEvent is a super class of all delegation model event classes.


There is one method called getID() in that class. What does that method
returns
A. text of the event
B. source of the event
C. ID of the event
 

 
 
 

19. What of the following cannot be added to a container ?


A. Applet
B. Panel
C. Frame
D. Component
E. Container
F. MenuComponent
 
 
 
 

20. How to initialise the variables in class Super from a constructor in the
sameclass(at line xx). Write a single line code without any spaces
 

class Super{

float x;

float y;

float z;

Super(float a, float b){

x = a;

y = b;

Super(float a, float b, float c){

//xx

z = c;

this(a,b);

21. What is true about inner classes?


A. Inner classes have to be instantiated only in the enclosing class
B. Inner classes can access all the final variables of the
enclosing class
C. Inner classes cannot be static
D. Inner classes cannot be anonymous class
E. Inner classes can extend another class.
 
 
 
 

22. Consider the following hierarchy


 

Parent

------------------------------

||

DerivedOne DerivedTwo

The following variables are initialised to null.

Parent P1;

DerivedOne D1;

DerivedTwo d2;

What will happen if the following assignment is made( take the above into
account)?

D1 = (DerivedOne) P1

A. It is legal at compile time and illegal at run time


B. It is legal at compile time and legal at run time // read q
properly, init to null
C. It is illegal at compile time.
D. It legal at compile time and may throw "CastClassException" at run
time
 

 
 
 

23. Which modifiers are to be used to obtain the lock on the object
A. public
B. private
C. static
D. synchornized
E. lock
 

 
 
 

24. // Point X

public class Example

What can be possibly used at Point X

A. import java.awt.*;
B. package local.util;
C. class NoExample{}
D. protected class SimpleExample
E. public static final double PI = 3.14;
 

 
 
 

25. What is the range of int type


 

-231 to 231-1

26. What are the legal identifers in Java?


A. %employee
B. $employee
C. employ-ee
D. employee1
E. _employee
 

 
 
 

27. Which of the following are true about the listener interfaces in Java ?
A. awt listener menthods generally takes an argument which is
an instance of some subclass of java.awt.AWTEvent
B. When multiple listeners are added to a single component the
order of invocation of the listeners cannot be guaranteed
C. A single component can have multiple listeners added to it.
 

 
 
 

28. Given the following declaration.


 

String S1 = "Hello";

Which of the following are true ?

A. S1 = S1 >> 2;
B. S1 += "there";
C. S1 += 3;
D. char c = S1[2]; // Will give an error, use chatAt, as String is aclass
not a Array
 

 
 
 

29. Given the following String declarations and methods. What is the String
object referred by S1 after execution of these statements ?

String S1 = "Hello";

String S2 = "There";

S1.concat(" my friend");

S1.concat(" our friend");

S1 += S2;

HelloThere

Você também pode gostar