What is assert? Where will you use it?

Asked 22-Jan-2018
Viewed 418 times

1 Answer


0

"Assert" is a keyword used in java which is used for testing purposes. it usually checks for a boolean value if the value is false it will throw an exception called assertion exception if true it will do nothing. before using assert it should be enabled. 

you can define assert in two ways-

assert expression;

or

assert expression1: expression2;  

if you want to use your message with an exception you can write

assert d != null : "d is null";