Anda di halaman 1dari 29

Question 1 of 61

What is the range of a 'char' data type?

Select 1 correct option.


a 0 - 65, 535
b 0 - 65, 536
c -32,768 - 32,767
d 0 - 32,767
e None of the above

Question 2 of 61

Consider the following code:


What would be the output when the above program is compiled and run?
public class TestClass
{
public void method(Object o)
{
System.out.println("Object Version");
}
public void method(java.io.FileNotFoundException s)
{
System.out.println("java.io.FileNotFoundException Version");
}
public void method(java.io.IOException s)
{
System.out.println("IOException Version");
}
public static void main(String args[])
{
TestClass tc = new TestClass();
tc.method(null);
}
}

Select 1 correct option.


a It will print, "Object Version"
b It will print, "java.io.IOException Version"
c It will print, "java.io.FileNotFoundException Version"
d It will not compile.
e It will throw an exception at runtime.
Question 3 of 61

What will be the ouput of the following program:


public class TestClass
{
public static void main(String args[])
{
try{
m1();
}catch(IndexOutOfBoundsException e){
System.out.println("1");
throw new NullPointerException();
}catch(NullPointerException e){
System.out.println("2");
return;
}catch (Exception e) {
System.out.println("3");
}finally{
System.out.println("4");
}
System.out.println("END");
}
// IndexOutOfBoundsException is a subclass of RuntimeException.
static void m1()
{
System.out.println("m1 Starts");
throw new IndexOutOfBoundsException( "Big Bang " );
}
}

Select 3 correct options


a The program will print 'm1 Starts'.
b The program will print 'm1 Starts', 1 and 4, in that order.
c The program will print 'm1 Starts', 1, 2 in that order.
d The program will print 'm1 Starts', 1, 2 and 4 in that order.
e 'END' will not be printed.
Question 4 of 61

Given the following set of member declarations, which of the following is true?
int a; // (1)
static int a; // (2)
int f( ) { return a; } // (3)
static int f( ) { return a; } // (4)

Select 2 correct options


a Declarations (1) and (3) cannot occur in the same class definition.
b Declarations (2) and (4) cannot occur in the same class definition.
c Declarations (1) and (4) cannot occur in the same class definition.
d Declarations (2) and (3) cannot occur in the same class definition.
e Declarations (1) and (2) cannot occur in the same class definition.

Question 5 of 61

How do you write decimal 7 in octal?


(Keep no space and no extra/unnecessary digits or semicolon)
Question 6 of 61

What will be the result of attempting to compile and run the following program?
public class TestClass
{
public static void main(String args[])
{
int x = 0;
labelA: for (int i=10; i<0; i--)
{
int j = 0;
labelB:
while (j < 10)
{
if (j > i) break labelB;
if (i == j)
{
x++;
continue labelA;
}
j++;
}
x--;
}
System.out.println(x);
}
}

Select 1 correct option.


a It will not compile.
b It will go in infinite loop when run.
c The program will write 10 to the standard output.
d The program will write 0 to the standard output.
e None of the above.
Question 7 of 61

What would be the result of compiling and running the following program?
class SomeClass
{
public static void main(String args[])
{
int size = 10;
int[] arr = new int[size];
for (int i = 0 ; i < size ; ++i) System.out.println(arr[i]);
}
}

Select 1 correct option.


a The code will fail to compile, because the int[] array declaration is incorrect.
b The program will compile, but will throw an
IndexArrayOutOfBoundsException when run.
c The program will compile and run without error, and will print nothing.
d The program will compile and run without error and will print null ten times.
e The program will compile and run without error and will print '0' ten times.

Question 8 of 61

Given the following program, which of these statements are true?


public class FinallyTest
{
public static void main(String args[])
{
try
{
if (args.length == 0) return;
else throw new Exception("Some Exception");
}
catch(Exception e)
{
System.out.println("Exception in Main");
}
finally
{
System.out.println("The end");
}
}
}

Select 2 correct options


a If run with no arguments, the program will only print 'The end'.
b If run with one argument, the program will only print 'The end'.
c If run with one argument, the program will print 'Exception in Main' and 'The
end'.
d If run with one argument, the program will only print 'Exception in Main'.
e Only one of the above is correct.

Question 9 of 61

Which is/are the root interface(s) for all collection related interfaces?

Select 2 correct options


a BaseCollection
b Collection
c List
d Set
e Map

Question 10 of 61

What, if anything, is wrong with the following code?


abstract class TestClass
{
transient int j;
synchronized int k;
final void TestClass(){}
static void f(){}
}

Select 1 correct option.


a The class TestClass cannot be declared abstract.
b The variable j cannot be declared transient.
c The variable k cannot be declared synchronized.
d The constructor TestClass( ) cannot be declared final.
e The method f( ) cannot be declared static.
Question 11 of 61

Which of the following are appropriate uses of assertions:


a.)
public void method()
{
int code = getCode(); // returns 0 or 1
if (code == 0) {
// deal with 0 ...
} else if (code == 1) {
// deal with 1 ...
} else {
assert false : "Can't process because code is
out of range -"+code;
}
}
b.)
public void method()
{
int code = getCode(); // returns 0 or 1
if (code == 0) {
// deal with 0 ...
} else {
assert code == 1 : "Can't process because code
is out of range -"+code;
// deal with 1
}
}
c.)
public void method()
{
int code = getCode(); // returns 0 or 1
switch(code)
{
case 0: // deal with 0 ...
break;
case 1: // deal with 1 ...
break;
default :
assert false : "Can't process because
code is out of range -"+code;
}
}

Select 1 correct option.


a a
b b
c c
d none of the above is appropriate.
e all of the above are appropriate.
Question 12 of 61

Which of the following statements are valid ?

Select 2 correct options


a String[ ] sa = new String[3]{ "a", "b", "c"};
b String sa[ ] = { "a ", " b", "c"};
c String sa = new String[ ]{"a", "b", "c"};
d String sa[ ] = new String[ ]{"a", "b", "c"};
e String sa[ ] = new String[ ] {"a" "b" "c"};

Question 13 of 61

What will be the result of attempting to compile and run the following code?
class SwitchTest
{
public static void main(String args[])
{
for ( int i = 0 ; i < 3 ; i++)
{
boolean flag = false;
switch (i)
{
flag = true;
}
if ( flag ) System.out.println( i );
}
}
}

Select 1 correct option.


a It will print 0, 1 and 2.
b It will not print anything.
c Compilation error.
d Runtime error.
e None of the above.

Question 14 of 61

Which of the following statements are true?

Select 2 correct options


a private keyword can never be applied to a class.
b synchronized keyword can never be applied to a class.
c synchronized keyword may be applied to a non-primitive variable.
d final keyword can never be applied to a class.
e A final variable can be shadowed in a subclass.

Question 15 of 61

Which of the following statements are true ?

Select 2 correct options


a System.out.println(~5 ); will not compile.
b System.out.println(~false ); will print true.
c System.out.println(!false ); will print true.
d System.out.println(!5 ); will not compile.

Question 16 of 61

Consider the following code:


class A
{
A() { print(); }
void print() { System.out.println("A"); }
}
class B extends A
{
int i = Math.round(3.5f);
public static void main(String[] args)
{
A a = new B();
a.print();
}
void print() { System.out.println(i); }
}

What will be the output when class B is run ?

Select 1 correct option.


a It will print A, 4.
b It will print A, A
c It will print 0, 4
d It will print 4, 4
e None of the above.
Question 17 of 61

Consider the following code snippet ...


boolean[] b1 = new boolean[2];
boolean[] b2 = {true , false};
System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) );

What will it print ?

Select 1 correct option.


a It will not compile.
b It will throw ArrayIndexOutOfBoundsError at Runtime.
c It will print false, true.
d It will print true, false.
e It will print false, false.

Question 18 of 61

After which line will the object passed to the method be eligible for garbage collection?
public void getObject(Object a)
{
Object c, b = new Object(); //1
//do something with a
c = b; //2
a = c;//3
b = a = null; //4
c = null;
}

Select 1 correct option.


a //1
b //2
c //3
d //4
e Never.
Question 19 of 61

Consider following classes:


//In File Other.java
package other;
public class Other { public static String hello = "Hello"; }
//In File Test.java
package testPackage;
import other.*;
class Test
{
public static void main(String[] args)
{
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello == hello) + " ");
//line 1
System.out.print((other.Other.hello == hello) + " "); //line 2
System.out.print((hello == ("Hel"+"lo")) + " "); //line 3
System.out.print((hello == ("Hel"+lo)) + " "); //line 4
System.out.println(hello == ("Hel"+lo).intern()); //line 5
}
}
class Other { static String hello = "Hello"; }
What will be the output of running class Test?

Select 1 correct option.


a false false true false true
b false true true false true
c true true true true true
d true true true false true
e None of the above.

Question 20 of 61

What should be the return type of the following method?


public RETURNTYPE methodX( byte by)
{
double d = 10.0;
return (long) by/d*3;
}

Select 1 correct option.


a int
b long
c double
d float
e byte
Question 21 of 61

Which of the given options can be successfully inserted at line 1....


//line 1
public class SomeClass { }

Select 3 correct options


a import java.lang.*;
b package p.util;
c public class MyClass{ }
d abstract class MyClass{ }

Question 22 of 61

What will be the result of attempting to compile and run the following program?
public class MyThread extends Thread
{
String msg = "default";
public MyThread(String s)
{
msg = s;
}
public void run()
{
System.out.println(msg);
}
public static void main(String args[])
{
new MyThread("String1").run();
new MyThread("String2").run();
System.out.println("end");
}
}

Select 1 correct option.


a The program will fail to compile.
b It will always print 'String1' 'String2' and 'end', in that order.
c It will always print 'String1' 'String2' in random order followed by 'end'.
d It will always print 'end' first.
e No order is guaranteed.

Question 23 of 61

Which of the following are valid identifiers?


Select 2 correct options
a class
b $value$
c angstrom
d 2much
e zer@

Question 24 of 61

What will be the output of the following program ?


public class TestClass
{
public static void main(String args[])
{
System.out.println(""+ ( (int) 8 ^10) + " , "+ ((int) 8 | 10 ) );
}
}

Select 1 correct option.


a 10 , 10
b 2,8
c 8 , 10
d 10, 8
e None of the above.

Question 25 of 61

You can only call public and protected constructors of the super class in a subclass if the
subclass is not in the same package because only those are inherited.

Select 1 correct option.


a True
b False

Question 26 of 61

Which of the following correctly tells about the effect of calling wait() method on an
object?
(Assume that the calling Thread has the lock of that object.)

Select 1 correct option.


a The thread that has called the wait() will stop executing until somebody notifies
it.
b The object issuing the call to wait() will halt until another object sends a notify()
or notifyAll() method
c An exception might be raised if it is not called in a synchronized block other
wise no exception will be raised.
d The thread calling wait() will be automatically synchronized with any other
threads who call wait().
e None of the above.

Question 27 of 61

What can be done so that the following program prints "tom", "dick" and "harry" in that
order?
public class TestClass extends Thread
{
String name = "";
public TestClass(String str)
{
name = str;
}
public void run()
{
try
{
Thread.sleep( (int) (Math.random()*1000) );
System.out.println(name);
}
catch(Exception e)
{
}
}
public static void main(String[] str) throws Exception
{
//1
Thread t1 = new TestClass("tom");
//2
Thread t2 = new TestClass("dick");
//3
t1.start();
//4
t2.start();
//5
System.out.println("harry");
//6
}
}

Select 1 correct option.


a Insert t1.join(); and t2.join(); at //4 and //5 respectively.
b Insert t2.join() at //5
c Insert t1.join(); t2.join(); at //6
d Insert t1.join(); t2.join(); at //3
e Insert t1.join() at //5

Question 28 of 61

Given the following class definitions, the expression


(obj instanceof C && !(obj instanceof D) )
correctly identifies whether the object referred to by obj was created by instantiating
class C rather than classes A, B and D?
class A {}
class B extends A {}
class C extends B {}
class D extends C {}

Select 1 correct option.


a True
b False

Question 29 of 61

Using a break in a while loop causes the loop to break the current iteration and start the
next iteration of the loop.

Select 1 correct option.


a True
b False

Question 30 of 61

Which of the following statements are true?

Select 3 correct options


a The condition expression in an if statement can contain method calls.
b If a and b are of type boolean, the expression (a = b) can be used as the condition
expression of an if statement.
c An if statement can have either an if clause or an else clause.
d The statement : if (false) ; else ; is illegal.
e Only expressions which evaluate to a boolean value can be used as the condition
in an if statement.
Question 31 of 61

Which of the following operators can be used in conjunction with a String object?

Select 3 correct options


a +
b ++
c +=
d .
e *

Question 32 of 61

Which of these array declarations and initializations are not legal?

Select 2 correct options


a int[ ] i[ ] = { { 1, 2 }, { 1 }, { }, { 1, 2, 3 } } ;
b int i[ ] = new int[2] {1, 2} ;
c int i[ ][ ] = new int[ ][ ] { {1, 2, 3}, {4, 5, 6} } ;
d int i[ ][ ] = { { 1, 2 }, new int[ 2 ] } ;
e int i[4] = { 1, 2, 3, 4 } ;

Question 33 of 61

Which of these methods are defined in the Map interface?

Select 2 correct options


a contains(Object o)
b addAll(Collection c)
c remove(Object o)
d values( )
e toArray( )
Question 34 of 61

The following class will never throw NullPointerException.


class Test
{
public static void main(String[] args) throws Exception
{
int[] a = null;
int i = a [ m1() ];
}
public static int m1() throws Exception
{
throw new Exception("Some Exception");
}
}

Select 1 correct option.


a True
b False

Question 35 of 61

Consider the following class...


class TestClass
{
int i;
public TestClass(int i) { this.i = i; }
public String toString()
{
if(i == 0) return null;
else return ""+i;
}
public static void main(String[ ] args)
{
TestClass t1 = new TestClass(0);
TestClass t2 = new TestClass(2);
System.out.println(t2);
System.out.println(""+t1);
}
}

What will be the output of the following program?

Select 1 correct option.


a It will throw NullPointerException when run.
b It will not compile.
c It will print 2 and then will throw NullPointerException.
d It will print 2 and null.
e None of the above.

Question 36 of 61

The following code snippet will print 'true'.


short s = Short.MAX_VALUE;
char c = s;
System.out.println( c == Short.MAX_VALUE);

Select 1 correct option.


a True
b False

Question 37 of 61

What will the following program print?


public class TestClass
{
static String str = "Hello World";
public static void changeIt(String s)
{
s = "Good bye world";
}
public static void main(String[] args)
{
changeIt(str);
System.out.println(str);
}
}

Select 1 correct option.


a "Hello World"
b "Good bye world"
c It will not compile.
d It will throw an exception at runtime.
e None of the above.
Question 38 of 61

Which of the following statements are true?

Select 1 correct option.


a Subclasses must define all the abstract methods that the superclass defines.
b A class implementing an interface must define all the methods of that interface.
c A class cannot override the super class's constructor.
d It is possible for two classes to be the superclass of each other.
e An interface can implement multiple interfaces.

Question 39 of 61

What will be the result of attempting to compile and run the following program?
public class TestClass
{
public static void main(String args[ ] )
{
StringBuffer sb = new StringBuffer("12345678");
sb.setLength(5);
sb.setLength(10);
System.out.println(sb.length());
}
}

Select 1 correct option.


a It will print 5.
b It will print 10.
c It will print 8.
d Compilation error.
e None of the above.
Question 40 of 61

Consider the contents of following two files:


//File A.java
package a;
public class A
{
A(){ }
public void print(){ System.out.println("A"); }
}
//File B.java
package b;
import a.*;
public class B extends A
{
B(){ }
public void print(){ System.out.println("B"); }
public static void main(String[] args)
{
new B();
}
}

What will be printed when you try to compile and run class B?

Select 1 correct option.


a It will print A.
b It will print B.
c It will not compile.
d It will compile but will not run.
e None of the above.

Question 41 of 61

Consider the following lines of code...


int a = 0x65;
byte b = 065;
char c = 65;
Which of the following statements are true?

Select 1 correct option.


a a == c is true but a == b is not true.
b Bit patterns for all the three are same.
c b == c is true but a == b is not true.
d a > c > b where a is largest and b is the smallest number.
e None of the above.
Question 42 of 61

An instance member ...

Select 2 correct options


a can be a variable, constant or a method.
b is a variable or a constant.
c belongs to the class.
d belongs to an instance of the class.
e is same as a local variable.

Question 43 of 61

What will be the result of attempting to compile and run the following program?
public class TestClass
{
public static void main(String args[ ] )
{
A o1 = new C( );
B o2 = (B) o1;
System.out.println(o1.m1( ) );
System.out.println(o2.i );
}
}
class A { int i = 10; int m1( ) { return i; } }
class B extends A { int i = 20; int m1() { return i; } }
class C extends B { int i = 30; int m1() { return i; } }

Select 1 correct option.


a The progarm will fail to compile.
b Class cast exception at runtime.
c It will print 30, 20.
d It will print 30, 30.
e It will print 20, 20.
Question 44 of 61

Given the following program, which of the lines would print exactly 6?
class TestClass
{
public static void main(String args[ ] )
{
float f = 6.5f;
System.out.println( Math.ceil(f) ); //1
System.out.println( Math.round(f) ); //2
System.out.println( Math.floor(f) ); //3
System.out.println( (int) Math.ceil(f) ); //4
System.out.println( (int) Math.floor(f) ); //5
}
}

Select 1 correct option.


a The line labeled 1
b The line labeled 2
c The line labeled 3
d The line labeled 4
e The line labeled 5

Question 45 of 61

Which of the following statements are true?

Select 2 correct options


a The extends keyword is used to specify inheritance.
b subclass of a non-abstract class cannot be declared abstract.
c subclass of an abstract class can be declared abstract.
d subclass of a final class cannot be abstract.
e A class, in which all the members are declared private, cannot be declared
public.

Question 46 of 61

Anonymous inner classes always extend directly from the Object class.

Select 1 correct option.


a True
b False
Question 47 of 61

How many objects will be eligible for GC just after the method returns?
public void compute(Object p)
{
Object a = new Object();
int x = 100;
String str = "abc";
}

Select 1 correct option.


a 0
b 1
c 2
d 3
e 4

Question 48 of 61

A programmer wants to ensure that assertions are enabled before rest of the method is
executed. He has written the following code:
public void someMethod()
{
boolean enabled = false;
assert enabled = true;
assert enabled;
... rest of the code ...
}

Which of the following statements are correct regarding the above code?

Select 1 correct option.


a It will throw an AssertionError() if assertions are disabled.
b It will throw an AssertionException() if assertions are disabled.
c It will throw a RuntimeException() if assertions are disabled.
d It will not compile.
e It will not throw anything if assertions are disabled.

Question 49 of 61

class java.lang.Void is standard java class for wrapping 'void' type. .

Select 1 correct option.


a True
b False
Question 50 of 61

What will the following program print?


public class TestClass
{
public static void main(String[] args)
{
for : for(int i = 0; i< 10; i++)
{
for (int j = 0; j< 10; j++)
{
if ( i+ j > 10 ) break for;
}
System.out.println( "hello");
}
}
}

Select 1 correct option.


a It will print "hello" 6 times.
b It will not compile.
c It will print "hello" 2 times.
d It will print "hello" 5 times.
e It will print "hello" 4 times.

Question 51 of 61

Consider this class:


class A
{
private int i;
public void modifyOther(A a1)
{
a1.i = 20; //1
}
}
State whether the following statememnt is true or false:
At //1 a1.i is valid.

Select 1 correct option.


a True
b False
Question 52 of 61

What will the following code print when compiled and run?
class A implements Cloneable
{
public int i = 10;

class B extends A
{
public int i = 20;

public class TestClass


{
public static void main(String args[]) throws Exception
{

B b1 = new B();
B b2 = b1.clone();
System.out.println(b1==b2);
System.out.println(new java.util.Date().getTime());

}
}

Select 1 correct option.


a It will print "true".
b It will print "false".
c It will not compile.
d It will throw an exception at run time.
e None of these.

Question 53 of 61

What will calling notify() method on an object implementing Runnable achieve?


(Assume that the calling thread has the lock of that object)

Select 1 correct option.


a Will cause the thread executing the run( ) method of the object to continue.
b Will cause a thread that had called the wait( ) method on that object to be
enabled for running.
c Will cause all the threads waiting for the monitor of the object to be enabled for
running.
d Will cause an IllegalmonitorStateException to be thrown.
e None of the above.

Question 54 of 61

What happens when you try to compile and run the following class...
public class TestClass
{
public static void main(String[] args) throws Exception
{
int a = Integer.MIN_VALUE;
int b = -a;
System.out.println( a+ " "+b);
}
}

Select 1 correct option.


a It throws an OverFlowException.
b It will print two same -ive numbers.
c It will print two different -ive numbers.
d It will print one -ive and one +ive number of same magnitude.
e It will print one -ive and one +ive number of different magnitude.
Question 55 of 61

Which statements can be inserted at line 1 in the following code to make the program
write x on the standard output when run?
public class AccessTest
{
String a = "x";
static char b = 'x';
String c = "x";
class Inner
{
String a = "y";
String get()
{
String c = "temp";
// Line 1
return c;
}
}
AccessTest() { System.out.println( new Inner().get() ); }
public static void main(String args[]) { new AccessTest(); }
}

Select 3 correct options


a c = c;
b c = this.a;
c c = ""+AccessTest.b;
d c = AccessTest.this.a;
e c = ""+b;

Question 56 of 61

Consider the following code:


public class Test extends Thread
{
static int x, y;
public synchronized void run(){ for(;;){ x++; y++;
System.out.println(x+" "+y);} }
public static void main(String[] args)
{
new Test().start();
new Test().start();
}
}
What will the above code print?

Select 1 correct option.


a It will keep on printin same values for x and y incrementing by 1 on each line.
b It will keep on printin same values for x and y but they may be incrementing by
more than 1 on each line.
c It may print different values for x and y but both the values will be incrementing
by 1 on each line.
d You cannot say anything about the values.

Question 57 of 61

Which of these statements are true?

Select 1 correct option.


a Transient variables will not be saved during serialization.
b Constructors can be declared abstract.
c The initial state of an array object constructed with the statement int a[ ] = new
a[10] will depend on whether the variable a[ ] is a local variable, or a member
variable of a class.
d Any subclasses of a class with an abstract method must implement a method
body for that method.
e Only static methods can access static members.

Question 58 of 61

Consider the following code fragment:


public void m1()
{
...
assert value == 10 : null;
}

Which of the following statement is correct regarding the above code?

Select 1 correct option.


a It will throw a NullPointerException if value is not equal to 10.
b It will throw a RuntimeException if value is not equal to 10.
c It will throw a AssertionError if value is not equal to 10.
d It will not compile because the second expression cannot be null.
e It will compile but will not throw any exception even if value is not equal to
null;

Question 59 of 61

Which of these collection implementations are thread-safe?


Select 1 correct option.
a ArrayList
b HashSet
c HashMap
d TreeSet
e None of the Above.

Question 60 of 61

Which of the following statements are true?

Select 1 correct option.


a To provide threading behaviour a class must extend Thread class.
b To provide threading behaviour a class must explicitly implement Runnable
interface.
c Threads created by user are always non-daemon threads.
d Thread created internally by the JVM are always daemon threads.
e None of the above are correct.

Question 61 of 61

The following code snippet will print true.


String str1 = "one";
String str2 = "two";
System.out.println( str1.equals(str1=str2) );

Select 1 correct option.


a True
b False

Anda mungkin juga menyukai