Posts

WAP that create interface on that you declare one method interest(p,r,n) then create two class simple and compound that implements interest and find simple and compound interest.

    /*1.  WAP that create interface on that you declare one method interest(p,r,n) then create two class  simple and compound that implements interest and find simple and compound interest. */ interface k1     {      void p();     } interface k2    {      void r();    }     interface k3    {      void n();    }   class Simple implements  k1,k2 {     public void p() { System.out.println("1 st");} public void r()  {System.out.println("2nd");} } class Compound implements  k3 {     public void n()  {   System.out.println(" 3rd");   } } class Kk    {     public static void main(String  []args)         {            Simple  s=new Simple(); ...

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

/*2.  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*/ interface p1    {        int a=10;       void A();    }   interface p2    {        int b=12;       void B();    }  interface p12 extends p1,p2    {        int c=44;       void C();    }       class   Q implements p12     {       public void A()    {  System.out.println("what is your number"+ a);}   public  void B()    {  System.out.println("what i...

WAP that demostrates the use of throw keyword in exception handling. main() method will call a(), a() calls b(), b() calls c() and method c(), b() and a() will throw an exception. Implement this hierarchy

/* WAP that demostrates the use of throw keyword in exception handling. main() method will call a(), a() calls b(), b() calls c() and method c(), b() and a() will throw an exception. Implement this hierarchy.*/ import java.io.*; class Tk   {                       void a() throws IOException { throw new IOException("error che bhai"); }       void b() throws IOException       {            a();          System.out.println("b che");       }       void c() {        try         {             b();             System.out.println("c che");               }          catch(Exception  e)       {     ...

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()); } ...

exception handle program example in java

/*6.1. Write a program that divides two numbers. Handle all exceptions that can be generated in this program.*/ class  E {    public static void main(String []args)      {         try          {           int a=5;         System.out.println(a/0);         System.out.println("just check karva ");      }       catch(ArithmeticException  e)        {             System.out.println("exceptin is ="  +e.getMessage());       } System.out.println("print thay k nai joy"); } } ************************************* default catch class  Etry {    public static void main(String []args)      {         try          {           int a=...

Example of array declaration

/*Write a program that creates and initializes a four integer element array. Calculate and display the average of its values.*/ import java.util.Scanner; class  K    {    public static void main(String []args)    {    Scanner b=new Scanner(System.in);       int[]   arr= new int[4];       int i;      System.out.println("enter element");         for(i=0; i<4; i++)        {            arr[i]=b.nextInt();      }        int sum=0;   for(i=0; i<4; i++)        {            sum=sum+arr[i];      }    System.out.println("avrage of element"+ (sum/2)); } }                                     ...

Example of abstract class

/*WAP that create abstract class figure. Declare area method in this class. class Rectangle and Circle inherits  class Figure.Write the method in all class that prints the area of respective Figure.*/  abstract class Ab    {    abstract   void area(); } class Rectangle extends Ab    {         int l,b;      void  area()    {       System.out.println("rectengle is="+(l*b));    }  } class circule extends Ab    {         int r;      void  area()    {       System.out.println("circule is="+(3.14*r*r));    }  }    class Abdemo { public static void main()   {      Ab  s1 =new Rectangle();     Ab  s2 =new circule();          s1.area();         s2.area();...