Professional Documents
Culture Documents
Which of the following statements regarding the above method are correct?
Given the following source code, which of the lines that are commented out may be
reinserted without introducing errors?
abstract class Bang
{
//abstract void f(); //(0)
final void g(){}
//final void h(){} //(1)
protected static int i;
private int j;
}
final class BigBang extends Bang
{
//BigBang(int n) { m = n } //(2)
public static void main(String args[])
{
Bang mc = new BigBang();
}
void h(){}
//void k(){ i++; } //(3)
//void l(){ j++; } //(4)
int m;
}
Select 1 correct option.
a final void h( ) { } //(1)
b BigBang(int n) { m = n } //(2)
c void k( ) { i++ } //(3)
d void l( ) { j++ } //(4)
e abstract void f( ) ; //(0)
Question 3 of 61
Question 4 of 61
Consider the following code in which searchBook() method has an inner class.
Which variables are accessible at line 1?
public class BookStore
{
private static final int taxId = 300000;
private String name;
public String searchBook( final String criteria )
{
int count = 0;
class Enumerator
{
String interate( int k)
{
//line 1
// lots of code.....
return "";
}
// lots of code.....
}
// lots of code.....
return "";
}
}
Question 6 of 61
Question 7 of 61
Question 8 of 61
Question 9 of 61
Question 10 of 61
Given :
byte b = 1;
char c = 1;
short s = 1;
int i = 1;
which of the following expressions are valid?
Question 12 of 61
Question 13 of 61
After which line may the object created at line 1 be garbage collected?
public class TestClass
{
public static Object getObj()
{
Object obj = new Object(); //1
Object obj2 = obj; //2
obj2 = null; //3
return obj; //4
}
public static void main(String[] args)
{
Object ob = getObj(); //5
ob = null; //6
}
}
Select 1 correct option.
a 2
b 3
c 4
d 5
e 6
Question 14 of 61
Given the following code, which of these constructors can be added to class B without
causing a compile time error?
class A
{
int i;
public A(int x) { this.i = x; }
}
class B extends A
{
int j;
public B(int x, int y) { super(x); this.j = y; }
}
Question 16 of 61
Question 17 of 61
Question 19 of 61
Question 21 of 61
When extending the Thread class to provide a thread's behaviour, which methods should
be overriden?
Question 23 of 61
Question 24 of 61
Question 25 of 61
Given the following class, which of these given blocks can be inserted at line 1 without
errors?
public class InitClass
{
private static int loop = 15 ;
static final int INTERVAL = 10 ;
boolean flag ;
//line 1
}
Question 27 of 61
Question 28 of 61
Following is a program to capture words from command line and create two collections.
One that keeps only unique words and one that keeps all the words in the order that they
were entered. What should replace AAA and BBB?
import java.util.*;
import java.io.*;
public class TestClass
{
static Collection unique = new AAA();
static Collection ordered = new BBB();
public static void main(String args[]) throws Exception
{
BufferedReader bfr = new BufferedReader( new InputStreamReader( System.in
));
String s = bfr.readLine();
while(s != null && s.length() >0)
{
unique.add(s);
ordered.add(s);
s = bfr.readLine();
}
System.out.println(unique);
System.out.println(ordered);
}
}
Question 30 of 61
Question 32 of 61
Question 33 of 61
An overloading method must have a different parameter list and same return type as that
of the overloaded method.
Select 1 correct option.
a True
b False
Question 34 of 61
Question 35 of 61
Consider that you are writing a set of classes related to a new Data Transmission Protocol
and have created your own exception hierarchy derived from java.lang.Exception as
follows:
java.lang.Exception
+-- enthu.trans.ChannelException
+-- enthu.trans.DataFloodingException, enthu.trans.FrameCollisionException
(I.e. both DataFlooding and FrameCollision are subclasses of ChannelException)
Your base class, "TransSocket" has a method declared as follows:
long connect(String ipAddr) throws ChannelException
You also want to write another "AdvancedTransSocket" class, derived from
"TransSocket" which overrides the above mentioned method. Which of the following are
valid declaration of the overriding method?
Question 38 of 61
What will be the result of attempting to compile and run the following code?
public class TestClass
{
public static void main(String args[] )
{
Outer out = new Outer();
System.out.println(out.getInner().getOi());
}
}
class Outer
{
private int oi = 20;
class Inner
{
int getOi() { return oi; }
}
Inner getInner() { return new Inner() ; }
}
Question 40 of 61
After which line will the object created at line XXX be eligible for garbage collection?
public Object getObject(Object a) //0
{
Object b = new Object(); //XXX
Object c, d = new Object(); //1
c = b; //2
b = a = null; //3
return c; //4
}
Question 42 of 61
Which of these statements concerning nested classes and interfaces are true?
Question 44 of 61
Question 45 of 61
Question 47 of 61
Question 49 of 61
What can be done to get the following code compile and run?
public float parseFloat( String s )
{
float f = 0.0f; // 1
try
{
f = Float.valueOf( s ).floatValue(); // 2
return f ; // 3
}
catch(NumberFormatException nfe)
{
f = Float.NaN ; // 4
return f; // 5
}
finally {
return f; // 6
}
return f ; // 7
}
Question 52 of 61
Consider the following code to count objects and save the most recent object ...
int i = 0 ;
Object prevObj ;
public void saveObject(List e )
{
prevObject = e ;
i++ ;
}
Which of the following calls will work without throwing an exception?
Question 54 of 61
Question 56 of 61
Question 57 of 61
Given the following code, which method declarations can be inserted at line 1 without
any problems?
public class OverloadTest
{
public int sum(int i1, int i2) { return i1 + i2; }
// 1
}
Question 59 of 61
Question 60 of 61
Which of the following statements regarding the assertion mechanism of Java is NOT
correct?
Question 61 of 61