File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exeption handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exeption handling" Watch "exeption handling" New topic
Author

exeption handling

Hasitha Randika
Ranch Hand

Joined: Sep 04, 2007
Posts: 50
what's the output of following code, will it give a compilation error,why?


public void divide(int a, int b) {

try {

int c = a / b;

} catch (Exception e) {

System.out.print("Exception ");

} finally {

System.out.println("Finally");

}
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hi hassel

What i can see from the code is

the variables a and b are method variables
can say local so they dont get any default value
and
if we try to use

method variables before
initialisation ie before assigning them any value
we get a compiler error

The above code will not compile


I hope this helps!!!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by dhwani mathur:
...the variables a and b are method variables
can say local so they dont get any default value...

The variables a and b are local to the method, but they are parameters. They need to be passed values in order for the method to be called.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Hassel:
what's the output of following code, will it give a compilation error,why? ...

This will not compile because it's only a method definition. If it were inside a class, then it would compile (assuming the missing brace were added).

To get output, you will need a main method that creates an instance of the class and calls this method. The output will depend on what int values you pass.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exeption handling
 
Similar Threads
mock question
q
Question from 4tests.com
mock question doubt
Rules Round-up (#132)