How to compile assert in Java?

Java 8Object Oriented ProgrammingProgramming

In order to compile assert in Java, we simply set the boolean expression as false.

Let us see an example program −

Example

 Live Demo

public class Example {
   public static void main(String[] args) {
      assert false;
      System.out.println("Compiled and executed successfully!!!");
   }
}

Output

Compiled and executed successfully!!!
raja
Published on 08-Jan-2019 14:58:30
Advertisements