Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Handling exception in overridden class

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Handling exception in overridden class

     
    import java.io.*;
    class A
    {
        public void display()
        {
            System.out.println("SuperClass");
        }
    }
    public class B extends A 
    {
       @Override
           public void display() throws IOException
           {
               System.out.println("SubClass");
           }
    }

    Here, A is base class and B is derived class.
    Now if method display() in class B throws IOException, it gives compile error.
    It says, overridden method does not throw java.io.IOException. What does that mean?
    But if it throws any other exception like ArithmeticException or NullPointerException, it works fine.
    So, what is the problem??
    Plzzz help.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Handling exception in overridden class

    overridden method does not throw java.io.IOException.
    You are trying to change the definition of the method.

    You have left off part of the error message. Please post the full text of the error message.
    Last edited by Norm; April 21st, 2012 at 03:58 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: Handling exception in overridden class

    throws IOException Did U Use In Second Method What U R Doing There I Didnt get You But If U R Throwing A Exception ,Exception Will Never Create Here N U R Throwing The IoException Just Try With Out That plz Give The Description What u Want To Do

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Handling exception in overridden class

    Quote Originally Posted by jitu.ideas2it View Post
    throws IOException Did U Use In Second Method What U R Doing There I Didnt get You But If U R Throwing A Exception ,Exception Will Never Create Here N U R Throwing The IoException Just Try With Out That plz Give The Description What u Want To Do
    Please write with proper grammar. Your post is virtually unreadable...'U' and 'plz' are not words

Similar Threads

  1. [SOLVED] exception handling
    By Topflyt in forum Exceptions
    Replies: 5
    Last Post: December 22nd, 2011, 12:00 PM
  2. [SOLVED] Exception Handling
    By Melawe in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2011, 07:39 PM
  3. Exception handling
    By JavaGirl9001 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 26th, 2011, 08:45 PM
  4. Exception Handling
    By hello_world in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 5th, 2011, 05:47 PM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM