Skip to main content

Java Day 4 (Assert)

 

Java Day 4

  1. What is the output of the following code?
  2. class ShellClass {
        public static void main(String[] args) {
            int x = 10;
            ;;;;;
            ;;;;;
            assert (x > 10);
        }
    }

Assert

Assertions are typically enabled when an application is being tested and deployed, but disabled when application is deployed.
-ea is used to enable assertion and -da is used to disable assertion.


class ShellClass {
    public static void main(String[] args) {
        int assert;
    }
}
class ShellClass {
    public static void main(String[] args) {
        assert "Hi";
    }
}
class ShellClass {
    public static void main(String[] args) {
        int x = 10;
        assert x > 10;
    }
}
class ShellClass {
    public static void main(String[] args) {
        int x = 10;
        assert x > 5 : "x is not greater than 5.";
        assert (x > 15) : "x is not greater than 15.";
        assert (x > 8) : "x is not greater than 8.";
    }
}
Prev Next

Comments