You are on page 1of 30

Question 1 of 61

In the following code what will be the output if 0 (integer value zero) is passed to
loopTest()?
(See Exhibit)
public class TestClass
{
public void loopTest(int x)
{
loop: for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
System.out.println(i);
if (x == 0) { continue loop; }
System.out.println(j);
}
}
}
}

Select 1 correct option.


a

The program will not compile.

It will print 1 2 3 4.

It will print 1 1 2 3 4

It will print 1 1 2 2 3 3 4 4

Produces no output

Question 2 of 61
Which line contains a valid constructor in the following class definition?
Question 12 of 61
Given the following class, which statements can be inserted at line 1 without causing the
code to fail compilation?
public class TestClass
{
int a;
int b = 0;
static int c;
public void m()
{
int d;
int e = 0;
// Line 1
}
}

Select 4 correct options


a

a++;

b++;

c++;

d++;

e++;

Question 13 of 61
Which lines contain a valid constructor in the following code?
public class TestClass
Select 1 correct option.
a

javajava

lavajava

javajavac

lavajavac

None of these.

Question 24 of 61
Consider the following class:
Which of the following statements are correct regarding the above class?
import java.util.*;
public class Info
{
String s1, s2, s3;
public Info(String a, String b, String c)
{
s1=a; s2=b; s3=c;
}
public boolean equals(Object obj)
{
if(! (obj instanceof Info) ) return false;
Info i = (Info) obj;
return (s1+s2+s3).equals(i.s1+i.s2+i.s3);
}
public int hashCode()
{
return s1.hashCode();
}
public static void main(String[] args)
{
Question 35 of 61
What will be the result of attempting to compile and run the following program?
public class Test extends Thread
{
String msg = "default" ;
public Test(String s)
{
msg = s;
}
public void run()
{
System.out.println(msg);
}
public static void main(String args[])
{
new Test("String1").start();
new Test("String2").start();
System.out.println("end");
}
}

Select 1 correct option.


a

The program will fail to compile.

It will always print 'String1' 'String2' and 'end', in that order.

It will always print 'String1' 'String2' in random order followed by 'end'.

It will always print 'end' first.

No order is guaranteed.
class SubClass extends BaseClass
{
public void print(String s)
{
System.out.println("SubClass :"+s);
// Line 1
}
public static void main(String args[])
{
SubClass sc = new SubClass();
sc.print("location");
} }

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

Question 44 of 61
Consider the following situation:
Thread T1 holds the lock for an object Obj. Thread T2 is has called obj.wait() and is
blocked.
What will allow the thread T2 to become runnable?

Select 1 correct option.


a

Thread T1 calls Thread.sleep(100).

Thread T2's wait() times out.

Thread T1 is interrupted.

Thread T1 releases the lock on Obj and calls the notify() method on T2.

Thread T1 releases the lock on Obj and calls the notify() method on Obj.

Question 45 of 61
a

instance { bool = true; }

InitTest() { si += 10; }

{ si = 5; i = bool ? 1000 : 2000;}

{ i = 1000; }

{ bool = (si > 5); i = 1000; }

Question 54 of 61
Consider:
o1 and o2 denote two different object references to different objects of same class.
Which of these statements are true?

Select 2 correct options


a

o1.equals(o2) is always false.

o1.hashCode( ) == o2.hashCode( ) is always false.

o1 == o2 is always false.
Question 1 of 61
What is the result of executing the following fragment of code:
boolean b1 = false;
boolean b2 = false;
if (b2 != b1 = !b2)
{
System.out.println("true");
}
else
{
System.out.println("false");
}

Select 1 correct option.


a

Compile time error.

It will print true.

It will print false.

Runtime error.

It will print nothing.

Question 2 of 61
Consider the following classes...
(See Exhibit)
Which of the following method declarations would be valid at line //1 ?
class Teacher
{
void teach(String student)
Question 13 of 61
Which of the following statements are true?

Select 2 correct options


a

An inner class may be declared static

Anonymous inner class may be declared public.

Anonymous inner class may be declared private.

Anonymous inner class may be declared protected.

Anonymous inner class may extend an abstract class.

Question 14 of 61
In the following code, after which statement (earliest), the object originally held in s, may
be garbage collected ?
Assume that there is a Student class with appropriate methods.
(See Exhibit)
1. public class TestClass
{
2. public static void main (String args[])
{
3. Student s = new Student("Vaishali", "930012");
4. s.grade();
5. System.out.println(s.getName());
6. s = null;
7. s = new Student("Vaishali", "930012");
8. s.grade();
9. System.out.println(s.getName());
10 s = null;
}
Question 25 of 61
Which of the following methods are available in the java.lang.Math class?

Select 4 correct options


a

double IEEEremainder(double, double)

double log(double a)

double log10(double a)

double rint(double a)

float max(float, float)

Question 26 of 61
Which of the following are valid declarations of the standard main() method?

Select 2 correct options


a

static void main(String args[ ]) { }

public static int main(String args[ ]) {}


Question 37 of 61
What will be the result of attempting to compile this class?
package test;
public class TopClass
{
public Inner inner1;
}
class Inner
{
int value;
}

Select 1 correct option.


a

The class will fail to compile, since the class Inner has not yet been declared when
referenced in class TopClass.

The class will fail to compile, since inner is a keyword.

The class will fail to compile, since you cannot write 2 classes in the same file.

The class will fail to compile, since the class Inner must be defined in a file called
Inner.java

The classes will compile.

Question 38 of 61
Expression ( s instanceof java.awt.Point ) will return false if 's' was declared as a
variable of class java.lang.String.
a

True

False

Question 49 of 61
What would be printed during execution of the following program?
public class TestClass
{
public static void main(String args[ ] )
{
shiftTest(1, "A" ) ;
shiftTest(1<<31, "B") ;
shiftTest(1<<30, "C") ;
shiftTest(-1, "D" ) ;
}
public static void shiftTest(int i , String str)
{
if (( i >> 1) != (i >>> 1)) System.out.println(str) ;
}
}

Select 2 correct options


a

d
Select 2 correct options
a

Question 61 of 61
Which of the following statements is correct?

Select 1 correct option.


a

new, delete and goto are keywords in the Java language

try, catch and thrown are keywords in the Java language

static, unsigned and long are keywords in the Java language


Question 1 of 61
Which statements concerning the following code are true?
class A
{
public A() {} // A1
public A(String s) { this(); System.out.println("A :"+s); } // A2
}
class B extends A
{
public int B(String s) { System.out.println("B :"+s); return 0; }
// B1
}
class C extends B
{
private C(){ super(); } // C1
public C(String s){ this(); System.out.println("C :"+s); } // C2
public C(int i){} // C3
}

Select 4 correct options


a

One of the constructors of each class is called as a result of constructing an object of class
C.

Constructor // A2 will never be called in creation of an object of class C

Class C can be instanciated only in two ways by users of this class.

// B1 will never be called in creation of objects if class A B or C

The code will not compile.

Question 2 of 61
Question 13 of 61
What will be the output of the following program?
public class TestClass
{
public static void main(String args[ ] )
{
int i = 0 ;
boolean bool1 = true ;
boolean bool2 = false;
boolean bool = false;
bool = ( bool2 & method1(i++) ); //1
bool = ( bool2 && method1(i++) ); //2
bool = ( bool1 | method1(i++) ); //3
bool = ( bool1 || method1(i++) ); //4
System.out.println(i);
}
public static boolean method1(int i)
{
return i>0 ? true : false;
}
}

Select 1 correct option.


a

It will print 1.

It will print 2.

It will print 3.

It will print 4.

It will print 0.
Question 25 of 61
Empty file is a valid source file.

Select 1 correct option.


a

True

False

Question 26 of 61
Which of the following are true about the "default" constructor?

Select 2 correct options


a

It is provided by the compiler only if the class does not define any constructor.

It initializes the instance members of the class.

It calls the default 'no-args' constructor of the super class.

It initializes instance as well as class fields of the class.

e
a

Using the setPriority( ) method in the class Thread.

Give the priority as a parameter to the constructor of the thread.

A thread can have priority from 1 to 10.

Thread Priorities are given by the OS.

None of the above.

Question 37 of 61
Which interface would you use to represent collection having non-unique objects in order?
(Do not uses spaces or other special characters)

Question 38 of 61
Which of the following will compile without any error?

Select 4 correct options


a
Select 1 correct option.
a

It will not compile.

It will throw ArrayIndexOutOfBoundsException when run.

It will print 1.

It will print 3.

It will print 4

Question 49 of 61
The following code snippet will print 4.
int i1 = 1, i2 = 2, i3 = 3;
int i4 = i1 + (i2=i3 );
System.out.println(i4);

Select 1 correct option.


a

True

False
Question 60 of 61
Which of the following classes extend the java.lang.Number class?

Select 4 correct options


a

java.lang.Integer

java.lang.Byte

java.lang.Character

java.lang.Double

java.lang.Short

Question 61 of 61
Which of the following is not a legal Java identifier?

Select 1 correct option.


a

num

int123
Question 1 of 61
Which of the following correctly declare a variable which can hold an array of 10 integers?

Select 2 correct options


a

int[ ] iA

int[10] iA

int iA[ ]

Object[ ] iA

Object[10] iA

Question 2 of 61
Consider the following class :
class Test
{
public static void main(String[] args)
{
for (int i = 0; i < 10; i++) System.out.print(i + " "); //1
for (int i = 10; i > 0; i--) System.out.print(i + " "); //2
int i = 20; //3
System.out.print(i + " "); //4
}
}

Which of the following statements are true?


Select 1 correct option.
a

It will print 'equal'.

It will print 'not equal'.

Compile time error at //1

Runtime error at //1

None of the above.

Question 12 of 61
Which of the following are correct ways to initialize the static variables MAX and
CLASS_GUID ?
class Widget
{
static int MAX; //1
static final String CLASS_GUID; // 2
Widget()
{
//3
}
Widget(int k)
{
//4
}
}

Select 2 correct options


a
Question 22 of 61
Which two of the following statements are equivalent?

Select 2 correct options


a

3*2^2

3<2

3<<2

3<<<2

3*4

Question 23 of 61
Which of the following statements are true?

Select 1 correct option.


a

For any non-null reference o1, the expression (o1 instanceof o1) will always yield true.

For any non-null reference o1, the expression (o1 instanceof Object) will always yield
Question 34 of 61
Which of the following statements are true?

Select 3 correct options


a

Interface Runnable is just a tag interface and has no methods.

Interface Runnable has one method.

class Thread implements Runnable.

All objects castable to Thread are castable to Runnable.

All objects castable to Runnable are castable to Thread.

Question 35 of 61
What is the name of the method that threads can use to pause their execution until
signalled by another thread to continue ?
(Do not include a parameter list or brackets or semicolon.)
Select 1 correct option.
a

1, 3

4, 5

2, 3

1, 2, 3

Question 46 of 61
Consider the following code that uses an assertion to ensure that the program is supplied
with 2 arguments:
public class TestClass
{
public static void main(String[] args)
{
assert args.length == 2 : "Must give two arguments";
...
}
}
Which of the given statements regarding the above code are correct?

Select 1 correct option.


a

This is an appropriate use of assertions.

b
Question 57 of 61
Which interfaces does java.util.Hashtable implement?

Select 1 correct option.


a

java.util.SortedSet

java.util.Map

java.util.SortedMap

java.util.TreeMap

java.util.List

Question 58 of 61
Given the following class definition:

class A
{
protected int i;
A(int i) { this.i = i; }
}
Which of the following would be a valid inner class for this class?

Select 2 correct options


Question 1 of 61
What will be the result of attempting to compile the following program?
public class TestClass
{
long l1;
public void TestClass(long pLong) {l1 = pLong ; } //(1)
public static void main(String args[])
{
TestClass a, b ;
a = new TestClass(); //(2)
b = new TestClass(5); //(3)
}
}

Select 1 correct option.


a

A compilation error will be encountered at (1), since constructors should not specify a
return value.

A compilation error will be encountered at (2), since the class does not have a default
constructor.

A compilation error will be encountered at (3).

The program will compile correctly.

It will not compile because parameter type of the constructor is different than the type of
value passed to it.

Question 2 of 61
What will be the output of the following program ?(See Exhibit)
class Test
Question 13 of 61
Which statements, when inserted at line 1, will cause a runtime exception ?
class B {}
class B1 extends B {}
class B2 extends B {}
public class ExtendsTest
{
public static void main(String args[])
{
B b = new B();
B1 b1 = new B1();
B2 b2 = new B2();
// insert statement here
}
}

Select 1 correct option.


a

b = b1;

b2 = b;

b1 = (B1) b;

b2 = (B2) b1;

b1 = (B) b1;

Question 14 of 61
Which statments about the output of the following programs are true?
Select 1 correct option.
a

Compilation error.

It will print 'Equal'.

It will print 'Not Equal'.

Runtime error.

None of the above.

Question 25 of 61
What application requirements may need you to use native methods?

Select 3 correct options


a

The application needs to do computation intensive job.

The application needs to access drivers for hardware that Java does not know about.

The application needs to make fields of a class globally available.


Question 36 of 61
If a synchronized method throws an exception in it's execution, the lock accquired by it is
released automatically.

Select 1 correct option.


a

True

False

Question 37 of 61
Given the following code fragment, which of the following lines would be a part of the
output?
outer:
for ( int i = 0 ; i<3 ; i++ )
{
for ( int j = 0 ; j<2 ; j++ )
{
if ( i == j )
{
continue outer;
}
System.out.println( "i=" + i + " , j=" + j );
}
}

Select 2 correct options


a

i = 1, j = 0

i = 0, j = 1

c
Question 48 of 61
Which of the following statements are true?

Select 1 correct option.


a

A program ends when all daemon threads end.

A program ends when all non-daemon threads end.

A program ends when all threads end.

A daemon thread is a low priority thread that never stops but keeps running in the back
ground.

A user thread cannot stop a non-user or daemon thread.

Question 49 of 61
What does the zeroth element of the string array passed to the standard main method
contain?

Select 1 correct option.


a

The name of the class.

b
a

Question 60 of 61
Which of the following statements are true?

Select 1 correct option.


a

The class Thread does not implement Runnable.

The class Thread is abstract.

Thread is an interface which has only one method, namely public void run();

Calling the method run( ) on an object castable to Thread will start the new thread.

You might also like