lecture-30a - Object Oriented Programming Java - Exceptions...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Object Oriented Programming Java - Exceptions & Assertions R.B. Lenin Winter 2006 DA-IICT 67 Assertions The new assertion feature is available only from Java 2 SDK 1.4. Be sure to use the right version when compiling and running programs with assertions. Object Oriented Programming Java - Exceptions & Assertions R.B. Lenin Winter 2006 DA-IICT 68 Assertions The syntax for the assert statement is assert <boolean expression>; where <boolean expression> represents the condition that must be true if the code is working correctly. If the expression results in false , an AssertionError (a subclass of Error ) is thrown. Object Oriented Programming Java - Exceptions & Assertions R.B. Lenin Winter 2006 DA-IICT 69 Assertions public double fromDollar(double dollar){ assert exchangeRate > 0.0; return (dollar * exchangeRate); } public double toDollar(double foreignMoney){ assert exchangeRate > 0.0; return (foreignMoney / exchangeRate); } Object Oriented Programming Java - Exceptions & Assertions R.B. Lenin Winter 2006 DA-IICT...
View Full Document

This note was uploaded on 09/15/2010 for the course CSE IT115 taught by Professor Rblenin during the Spring '10 term at Punjab Engineering College.

Page1 / 12

lecture-30a - Object Oriented Programming Java - Exceptions...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online