Explain the assertion construct?

The assertion statements have two forms as shown below:

assert Expression1;
assert Expression1 : Expression2;

Where:

  • Expression1 -> is a boolean expression. If the Expression1 evaluates to false, it throws an AssertionError without any detailed message.
  • Expression2 -> if the Expression1 evaluates to false throws an AssertionError with using the value of the Expression2 as the error’s detailed message.

Note: If you are using assertions (available from JDK1.4 onwards), you should supply the JVM argument to enable it by package name or class name.

java -ea[:packagename...|:classname] or java -enableassertions[:packagename...|:classname]
java –ea:Account

											
Tagged . Bookmark the permalink.

Leave a Reply