File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Exam Q#60 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Exam Q#60" Watch "Marcus Exam Q#60" New topic

Marcus Exam Q#60

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Question 60)
Given the following code
public class Ppvg{
public static void main(String argv[]){
Ppvg p = new Ppvg();
public int fliton(){
DataInputStream din = new DataInputStream(;
}catch(IOException ioe){
return 99;

return -1;

Which of the following statements are true if you try to compile and run the program?
1) The program will run and output only "flytwick"
2) The program will run and output only "fliton"
3) The program will run and output both "fliton" and "flytwick"
4) An error will occur at compile time because the method fliton attempts to return two values
The answer is 2.
The program will run and output only "fliton"
From the answer it looks that the code in the try block is not throwing any exception ,that's why catch block is being by
passed and it prints the statement in the finally block, how one can know that there is no exception is being thrown from the try block?? if it is printig the statment of finally block , why not it also retuns -1, which is being returned from finally block???
If someone can explain :
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

You are absolutely correct in saying it will also
return -1. However, IMO we should answer based on the
choices we have. In the available answers, choice 2
best suits the question.
Keep in mind that the author is assuming that
no exceptions are being thrown, though such a
stmt is not mentioned in the qstn. IMO, this qstn should
be worded to include "if the try block does not throw
any exceptions
Anyways, the return value is -1 if no exceptions
occur and is 99 if IOException is caught.
- satya
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
If really the question does not mention whether an exception is thrown or not, then there is no way to answer this question and you can not make the darling assumption that an exception is not thrown. In the real exam, you will never be required to make such an unrealistic assumption.The exam will explicitly tell you whether an exception is thrown or not,and you will answer based on accurate facts.
Good luck,
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks Satya and Herbert..I am now clear about this..
I agree. Here's the link:
subject: Marcus Exam Q#60
jQuery in Action, 3rd edition