You are on page 1of 6

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.
b It will print true.
c It will print false.
d Runtime error.
e 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)
{
/* lots of code */
}
}
class Prof extends Teacher
{
//1
}

Select 4 correct options


a public void teach() throws Exception
b private void teach(int i) throws Exception
c protected void teach(String s)
d public final void teach(String s)
e public abstract void teach(String s)
Question 3 of 61

Which one of these is a proper definition of a class TestClass that cannot be sub-classed?

Select 1 correct option.


a final class TestClass { }
b abstract class TestClass { }
c native class TestClass { }
d static class TestClass { }
e private class TestClass { }

Question 4 of 61

The following class will print '2' when compiled and run.
class Test
{
public static int[ ] getArray() { return null; }
public static void main(String[] args)
{
int index = 1;
try
{
getArray()[index=2]++;
}
catch (Exception e){ } //empty catch
System.out.println("index = " + index);
}
}

Select 1 correct option.


a True
b False

Question 5 of 61

Consider the following code...


What should replace XXXX?
public class TestClass
{
class MyException extends Exception {}
public void myMethod() throws XXXX
{
throw new MyException();
}
}

Select 3 correct options


a MyException
b Exception
c No throws clause is necessary
d Throwable
e RuntimeException

Question 6 of 61

What letters, and in what order, will be printed when the following program is compiled
and run?
(See Exhibit)
public class FinallyTest
{
public static void main(String args[]) throws Exception
{
try
{
m1();
System.out.println("A");
}
finally
{
System.out.println("B");
}
System.out.println("C");
}
public static void m1() throws Exception { throw new Exception(); }
}

Select 1 correct option.


Question
a 7 of
It will 61C and B, in that order.
print
b It will print A and B, in that order.
What
c will be the output of the following class...
It will print B and throw Exception.
d
class ItTest
will print A, B and C in that order.
{
e Compile time error.
public static void main(String[] args)
{
int j = 1;
try
{
int i = doIt() / (j = 2);
} catch (Exception e)
{
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception { throw new
Exception("FORGET IT"); }
}

Select 1 correct option.


a It will print j = 1;
b It will print j = 2;
c The value of j cannot be determined.
d It will not compile.
e None of the above.
Question 8 of 61

Consider the following two methods ...


public int leftShift(int number, int by)
{
return number << by;
}
public int rightShift(int number, int by)
{
return number >> by;
}
And the code snippet :
{
int i = 1;
i = leftShift(i, 31);
i = rightShift(i, 31);
System.out.println(i); //1
}

What will line 1 print ?

Select 1 correct option.


a Some +ive number greater than 1.
b Some big -ive number less than 1.
c It will print 0.
d It will print 1
e It will print -1

Question 9 of 61

Which of these statements are true?

Select 3 correct options


a The compiler will fail to compile code that explicitly tries to call the finalize
method.
b The finalize method must be declared with protected accessibility.
c If an object is being collected by the GC then it's finalize() method is guaranteed
to be called.
d finalize method can be overloaded.
e You can give any exception in throws clause of finalize() method.
Question 10 of 61

What will the following program print ?(See Exhibit)


class Test
{
public static void main(String[] args)
{
int i = 4;
int ia[][][] = new int[i][i = 3][i];
System.out.println( ia.length + ", " + ia[0].length+", "+
ia[0][0].length);
}
}

Select 1 correct option.


a It will not compile.
b 3, 4, 3
c 3, 3, 3
d 4, 3, 4
e 4, 3, 3
Question 15
11 of 61

Consider
Which of the
the following
following class:
statements are true?
public class GoodOne
Select 2 correct options
{
a The modulus
int theval;operator % can only be used with integer operands.
b & public
can haveint
integral as well as boolean operands.
hashCode()
c {
The arithmetic operators *, / and % have the same level of precedence.
return theval%3;
d && } can have integer as well as boolean operands.
e ~ can have boolean
public integer as equals(Object
well as boolean operands.
obj)
{
Question 16 of 61
// 1 insert code here.
}
Consider
} the following class...
class
Which ofMyString extends
the following String
options may be insterted at //1?
{
MyString(){ super(); }
Select
} 1 correct option.
a return true;
b above
The return
code
theval%3
will not==
compile.
0? true :false;
c return theval%2 == 0? true :false;
Select
d 1return
correct option.
( (int)Math.random())*10%3 == 0? true :false;
a
e True
return false;
b False

Question 17 of 61

Which operators will always evaluate all the operands?

Select 2 correct options


a &&
b |
Question
c || 19 of 61
d ?:
Consider
e % the following classes...
class Car
{
public int gearRatio = 8;
public String accelerate() { return "Accelerate : Car"; }
Question
} 57 of 61
class SportsCar extends Car
Consider
{ the following code snippet:
public int gearRatio = 9;
XXXXpublic
m ; String accelerate() { return "Accelerate : SportsCar"; }
switch(
public mstatic
) void main(String[] args)
{{
case
Car 32
c = : new
System.out.println("32");
SportsCar(); break;
case
System.out.println(
64 : System.out.println("64");
c.gearRatio+" "+c.accelerate()
break; );
} case 128 : System.out.println("128"); break;
} }
What type
will be
canprinted
'm' be when
of so that
SportsCar
the above
is run?
code compiles and runs as expected ?

Select 31 correct options


option.
a 8 Accelerate
int m; : Car
b 9 Accelerate
long m; : Car
c 8 Accelerate
char m; : SportsCar
d 9 Accelerate
byte m; : SportsCar
e None m;
short of the above.

You might also like