WAP that creates a custom exception InvalidAgeException which will be thrown when user enters age below 18.

 WAP that creates a custom exception InvalidAgeException which will be thrown when user enters age below 18.




import  java.util.Scanner;
class Exc
{
 public static void main(String []args)
   {
     Scanner s=new Scanner(System.in);
    System.out.println(" enter your age");
      int age = s.nextInt();
         try
              {
                if(18<age)
                throw new ArithmeticException("your age is 18+");
                   else
                  System.out.println("you age considered") ;
                 }
catch(ArithmeticException e)
{
   System.out.println("Exception is="+ e.getMessage());
}
System.out.println("bs have ");
}
}
     
             
 
 

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

Example of abstract class