Throw exception

 public class ThrowExample {

 static void checkAge(int age) {

 if (age < 18)

 throw new ArithmeticException("Not eligible");

 else

 System.out.println("Eligible");

 }

 public static void main(String[] args) {

 checkAge(16);

 }

}


Comments

Popular posts from this blog

10. Vehicle and Car

Interface with Rectangle

Multiple interface