Professional Documents
Culture Documents
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.
b It will print 1 2 3 4.
c It will print 1 1 2 3 4
d It will print 1 1 2 2 3 3 4 4
e Produces no output
Question 2 of 61
Which of the following options can be a part of a correct inner class declaration or a
combined declaration and instance initialization ?
Question 4 of 61
What will happen when the above code is compiled and run?
Question 6 of 61
Question 7 of 61
Question 8 of 61
Which of the following code segments will correctly double the value of an integer i ?
Question 9 of 61
Question 11 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
}
}
Question 13 of 61
What will be the result of attempting to compile and run the following program?
Question 16 of 61
Question 17 of 61
Question 18 of 61
In which of these variable declarations, will the variable remain uninitialized unless
explicitly initialized?
Question 19 of 61
Which is the earliest line in the following code after which the object created on the //1
can be garbage collected, assuming no compiler optimizations are done?
Question 20 of 61
Question 21 of 61
Question 22 of 61
Question 23 of 61
Question 29 of 61
Question 30 of 61
Which of the following access control keywords can be used to enable all the subclasses
to access a method defined in the base class?
Question 31 of 61
Which of the following will not give any errors at compile and run time?
Question 33 of 61
Which statements concerning the value of a member variable are true, when it is not
initialized explicitly?
Question 34 of 61
How can you declare 'i' so that it is not visible outside the package 'test'.
package test;
class Test
{
XXX int i;
/* lot of code */
}
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");
}
}
Which digits, and in which order, will be printed when the following program is run?
(See Exhibit)
public class TestClass
{
public static void main(String args[])
{
int k = 0;
try{
int i = 5/k;
}
catch (ArithmeticException e){
System.out.println("1");
}
catch (RuntimeException e){
System.out.println("2");
return ;
}
catch (Exception e){
System.out.println("3");
}
finally{
System.out.println("4");
}
System.out.println("5");
}
}
Which of these statements concerning the use of standard collection interfaces are true?
Which of the following statements concerning the switch construct are true?
Question 41 of 61
Consider :
class A {}
class B extends A {}
class C extends B {}
Which of these boolean expressions correctly identifies when an object 'o' acutally refers
to an object of class B and not of C?
Question 42 of 61
What interface can a class implement so that it can execute in a seperate thread?
Question 43 of 61
Write a line of code that, when inserted at line 1, will make the overriding method in
SubClass invoke the overridden method in BaseClass on the current object with the same
parameter.
class BaseClass
{
public void print(String s) { System.out.println("BaseClass :"+s); }
}
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
Question 45 of 61
Question 46 of 61
What will be the output of compiling and running the following program:
class TestClass implements I1, I2
{
public void m1() { System.out.println("Hello"); }
public static void main(String[] args)
{
TestClass tc = new TestClass();
( (I1) tc).m1();
}
}
interface I1
{
int VALUE = 1;
void m1();
}
interface I2
{
int VALUE = 2;
void m1();
}
What will be the output when the following program is compiled and run?
(See Exhibit)
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
{
Thread t1 = new TestClass("tom");
Thread t2 = new TestClass("dick");
t1.start();t2.start();
t1.join(); t2.join();
System.out.println("harry");
}
}
Question 49 of 61
Question 50 of 61
Question 51 of 61
Question 52 of 61
Question 53 of 61
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?
Question 55 of 61
Which statements concerning the relation between the non static inner classes and their
outer class instances are true?
Question 56 of 61
What will happen when the above classes are compiled and class B is run?
Question 58 of 61
Question 59 of 61
Question 60 of 61
Question 61 of 61