This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Java Rules Roundup #47 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Java Rules Roundup #47" Watch "Java Rules Roundup #47" New topic

Java Rules Roundup #47

Joseph Maddison
Ranch Hand

Joined: Nov 04, 2004
Posts: 53
(#47) What happens when you divide an integer by a variable with a value of 0?

o Compiler Error
o Compiles and Runs
o Runtime Exception

Doesn't the answer depend on information that is not presented in the question, namely the type of the second variable?

Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I think there is a little bit of an assumption here that because the variable has the value 0 it is either int, byte, short, or char. Any of these will throw a runtime error.

Where I think this question gets a little off is that you can do the following.

double a = 0;

and you don't get a compile or runtime error.
Mukesh Poddar

Joined: Jan 14, 2005
Posts: 8
If u did't assume that the Data type of the second variable integer then only it will give the runtime Airthmetic Exception

Otherwise if one of the value is float/double then it will Run succesfully

It is sorta covered in the JavaRanch Style Guide.
subject: Java Rules Roundup #47
Similar Threads
Take the Dr. Phil Test
doubt in has-a relationship
JApplet + JPanel + image.jpg
Tomcat Error, New Install
SCMAD books ...