Professional Documents
Culture Documents
Question 2 of 61
Question 3 of 61
Given a class named Test, which of these would be valid definitions for the constructors
for the class?
Question 4 of 61
How many strings are eligible to be garbage collected after the execution of line 2 and
line 4?
public class TestClass
{
public static void main(String args[])
{
String str0 = null;
String str1 = new String("some string");
String str2 = new String("second string");
String str3 = new String("Third string");
str0 = str1; //1
str1 = null; //2
str2 = str0; //3
str3 = str2; //4
}
}
Question 6 of 61
Question 8 of 61
Which one of these is a proper definition of a 'class Car' that cannot be sub-classed?
Question 10 of 61
What will be printed when the following program is compiled and run?
class Super
{
public int getNumber( int a)
{
return 2;
}
}
public class SubClass extends Super
{
public int getNumber( int a, char ch)
{
return 4;
}
public static void main(String[] args)
{
System.out.println( new SubClass().getNumber(4) );
}
}
Question 13 of 61
Question 14 of 61
Which statments about the output of the following programs are true?
public class TestClass
{
public static void main(String args[ ] )
{
int i = 0 ;
boolean bool1 = true;
boolean bool2 = false;
boolean bool = false;
bool = (bool2 & method1("1")); //1
bool = (bool2 && method1("2")); //2
bool = (bool1 | method1("3")); //3
bool = (bool1 || method1("4")); //4
}
public static boolean method1(String str)
{
System.out.println(str);
return true;
}
}
Question 16 of 61
What can be done to let the following code compile and run without errors?
class SomeClass
{
String s1 = "green mile"; // 0
public void generateReport( int n )
{
String local; // 1
if( n > 0 ) local = "good"; //2
System.out.println( s1+" = " + local ); //3
}
}
Question 17 of 61
Question 18 of 61
What would be the result of attempting to compile and run the following program?
class TestClass
{
static TestClass ref;
String[] arguments;
public static void main(String args[])
{
ref = new TestClass();
ref.func(args);
}
public void func(String[] args)
{
ref.arguments = args;
}
}
Question 20 of 61
Question 21 of 61
Question 23 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[ ] )
{
String s = "hello";
StringBuffer sb = new StringBuffer("hello");
sb.reverse();
s.reverse();
if( s == sb.toString() ) System.out.println("Equal");
else System.out.println("Not Equal");
}
}
Question 25 of 61
Question 26 of 61
Which of these exceptions can be thrown by the wait() method of the Object class?
Which of these implementations for collection framework interfaces are provided in the
standard JDK?
Question 29 of 61
Which of the following statements regarding 'break' and 'continue' are true?
Question 31 of 61
Question 32 of 61
Question 33 of 61
Question 34 of 61
What will be the result of compiling and running the following program ?
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExcceptionTest
{
public static void main(String [] args) throws Exception
{
try
{
m2();
}
finally{ m3(); }
}
public static void m2() throws NewException{ throw new
NewException(); }
public static void m3() throws AnotherException{ throw new
AnotherException(); }
}
Question 35 of 61
Question 36 of 61
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 );
}
}
Question 39 of 61
What happens when you try to compile and run the following program?
public class CastTest
{
public static void main(String args[ ] )
{
byte b = -128 ;
int i = b ;
b = (byte) i;
System.out.println(i+" "+b);
}
}
Question 40 of 61
Question 41 of 61
Which of the following method definitions will prevent overriding of that method?
Question 43 of 61
Question 44 of 61
Question 45 of 61
Question 46 of 61
Question 47 of 61
Which of the given statements are correct about the following code?
// Filename: TestClass.java
class TestClass
{
public static void main(String[] args)
{
A a = new A();
B b = new B();
};
}
class A implements T1, T2{}
class B extends A implements T1{}
interface T1 { }
interface T2 { }
Question 48 of 61
Question 49 of 61
What does the zeroth element of the string array passed to the standard main method
contain?
Question 50 of 61
Question 52 of 61
Question 53 of 61
Question 54 of 61
For a class that stores associations of key - values, which of these interfaces it looks like?
A programmer has written the following code to ensure that the phone number is not null
and is of 10 characters:
public void processPhoneNumber(String number)
{
assert number != null && number.length() == 10 :
"Invalid phone number";
...
}
Which of the given statements regarding the above code are correct?
Question 56 of 61
Question 57 of 61
Question 58 of 61
How can you declare a method someMethod() such that an instance of the class is not
needed to access it and all the members of the same package have access to it.
Question 60 of 61
Question 61 of 61