What is assert? Where will you use it?

Asked 7 years ago
Viewed 490 times

1

What is assert? Where will you use it?


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";


answered 7 years ago by Prateek sharma

Your Answer