aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Exam Q#60" Watch "Marcus Exam Q#60" New topic
Author

Marcus Exam Q#60

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Question 60)
Given the following code
import java.io.*;
public class Ppvg{
public static void main(String argv[]){
Ppvg p = new Ppvg();
p.fliton();
}
public int fliton(){
try{
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}catch(IOException ioe){
System.out.println("flytwick");
return 99;
}finally{
System.out.println("fliton");
}

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 :
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

Wali:
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.
Regds.
- 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,
Herbert.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks Satya and Herbert..I am now clear about this..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Exam Q#60
 
Similar Threads
Please help me!
exceptions
return value
Marcus Mock 3 question #60
return statement