Results 1 to 2 of 2
  1. #1
    1202910120 is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Exception handling in the below code

    Java Code:
    import java.io.*;
     interface my1
     {
     public void like()throws IOException;
     }
     interface my2
     {
     public void like() ;
     }
     public class interface1 implements my1,my2 {
     public void like() 
     {
     try
     {
     InputStreamReader in=new InputStreamReader(System.in);
     BufferedReader br=new BufferedReader(in);
     int a=Integer.parseInt(br.readLine());
     System.out.println(a);
    
    
    }
     catch(Exception e)
     {
     e.printStackTrace();
     }
    
    }
     public static void main(String aa[])
     {
     my2 obj=new interface1();
     obj.like();
     }
     }
    here why I am getting the run-time error that could not load main find or load man class interface1.

    Also in the second case if I make the like method in my2 interface also like

    public void like() throws IOException ; Now I get a compile-time error that unreported exception ,so error is at line obj.like() ,even when I make the like method in interface1 as
    public void like() throws IOException
    {
    }

    Still I am getting the error at obj.like() line same as above,And I am unable to make out the reason for this .

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Exception handling in the below code

    With the poor formatting of the code, it is hard to see the code's structure.
    Could you edit your post and fix the code's indentations so it is readable?

    I am getting the run-time error
    Also please copy the full contents of the command prompt window from when you try to execute the code.
    It should show the command that was entered and all error messages.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Exception handling
    By ExX in forum New To Java
    Replies: 6
    Last Post: 03-12-2012, 11:48 AM
  2. Exception handling
    By Moedig in forum New To Java
    Replies: 2
    Last Post: 11-10-2011, 10:43 PM
  3. Replies: 3
    Last Post: 08-10-2011, 09:17 AM
  4. Exception Handling
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 02-20-2011, 12:00 AM
  5. Exception Handling help
    By MZA in forum New To Java
    Replies: 3
    Last Post: 02-10-2010, 09:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •