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: Java code problems!

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Java code problems!

    There are two errors in this class, what are they? and how do I fix them?

     public class Question04c extends OtherClass{
    protected int answer(int i) throws DumbQuestionException { if(i < 0){ throw
        new DumbQuestionException(); } else return 6; } }
    class OtherClass{ public int answer(int i){ return i; } }
        class DumbQuestionException extends Exception{ }


  2. #2
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Java code problems!

    First, overriden answer() cannot throw exception, because it's parent didn't. Second, overriden method cannot have more narrow scope then parent.
    P.S.: your style is awful

  3. The Following User Says Thank You to angstrem For This Useful Post:

    frenchsasha (May 26th, 2013)

  4. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java code problems!

    @angstrem Please beware of giving answers to homework questions. Especially when the question was no more effort than copy paste. But at the same time also thanks for the help answering questions on the forum.
    Please see The problem with spoonfeeding.
    @frenchsasha Someone will be getting a new assignment

  5. #4
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Java code problems!

    @jps I'm really sorry. I will consider it.

Similar Threads

  1. Code problems
    By Alucard2487 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 27th, 2013, 05:02 PM
  2. problems with my code
    By poppe in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2012, 09:10 AM
  3. Problems with my code
    By poppe in forum Member Introductions
    Replies: 1
    Last Post: January 26th, 2012, 04:53 AM
  4. Problems with a code
    By oriol in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 9th, 2011, 07:02 PM
  5. Problems with Code?
    By Sean137 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 14th, 2010, 02:15 PM

Tags for this Thread