hi,
given below is a mock xam question.
question:
--------
public int increment() {
try {
counter += 2;
System.out.write(counter);
}
finally { counter--; }
return counter;
}
What is wrong with method increment()?
options:
--------
* the "finally" code block must include a return statement
* the method should be synchronized
* there is no "catch" block
* outputstream "out" must be opened inside increment()
* finally() can not access class variables
i tried revamping the code and it is successfully working(ie no output is being displayed) but even then i don't have any clue to what the correct answer is.
revamped code:
-------------
class rf2
{
int counter=0;
public int increment()
{
try
{
counter += 2;
System.out.write(counter);
}
finally
{
counter--;
}
return counter;
}
public static void main(
String a[])
{
rf2 o = new rf2();
o.increment();
}
}
could u please help?
arun.