Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Question 2 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)
Question 5 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);
}
}
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]);
}
}
Question 8 of 61
Question 9 of 61
Which is/are the root interface(s) for all collection related interfaces?
Question 10 of 61
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 );
}
}
}
Question 14 of 61
Question 15 of 61
Question 16 of 61
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;
}
Question 20 of 61
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");
}
}
Question 23 of 61
Question 24 of 61
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.
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.)
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
}
}
Question 28 of 61
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.
Question 30 of 61
Which of the following operators can be used in conjunction with a String object?
Question 32 of 61
Question 33 of 61
Question 35 of 61
Question 36 of 61
Question 37 of 61
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());
}
}
What will be printed when you try to compile and run class B?
Question 41 of 61
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; } }
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
}
}
Question 45 of 61
Question 46 of 61
Anonymous inner classes always extend directly from the Object class.
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";
}
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?
Question 49 of 61
Question 51 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;
B b1 = new B();
B b2 = b1.clone();
System.out.println(b1==b2);
System.out.println(new java.util.Date().getTime());
}
}
Question 53 of 61
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);
}
}
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(); }
}
Question 56 of 61
Question 57 of 61
Question 58 of 61
Question 59 of 61
Question 60 of 61
Question 61 of 61