Hi, All.

Here is the sequence of java access levels:
public->protected->default->private

As public is the strongest so child's method can only be public. And
it can throw only IOException or its subclasses or nothing at all.

import java.io.IOException;

class Farther{

    public void FarthersMethod() throws IOException {
        throw new IOException();
    }

}

class Son extends Farther{

    public void FarthersMethod() throws IOException {
    }

}

The following is wrong:

class Son extends Farther{

    private void FarthersMethod() throws IOException {
    }

}

class Son extends Farther{

    public void FarthersMethod() throws Exception {
    }

}

On Oct 18, 8:38 pm, Nirmal Kumar <nirmal.h...@gmail.com> wrote:
> Hi All,
>
> Can anyone explain the following Method Overriding Rules in Java:
>
> The access level *cannot be more restrictive* than the overridden method's
> access level.
> However the access level *can be less restrictive* than the overridden
> method's access level.
>
> The overridden method should not throw checked exceptions that are new or
> broader than the ones declared by the overridden method.
> The overriding method can throw narrower or fewer exceptions than the
> overridden method.
>
> Please give an example if possible.
>
> Thanks,
> Nirmal
>
>                  \\\///
>               /         \
>               | \\   // |
>             ( | (.) (.) |)
> ----------o00o--(_)--o00o-------------------
> Stand up,be bold,be strong.
> Take the whole responsibility on
> ur own shoulders and know that
> U are the creator of ur own destiny.
> ------ooo0-------------------------------------
>     (   )     0ooo
>      \ (      (   )
>       \_)      ) /
>               (_/

-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Reply via email to