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 FarthersMe
class Parent{
public void methodA(){
}
}
class Child{
private void methodA(){ //private method not possible so The
access level *cannot be more restrictive* than the overridden method's
access level.
}
}
class Parent{
public void methodA() throws IOException{
}
}
class Child{
pub
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.
Here is an example:
Lets say you are overriding: public void doSomething{}
Well you cannot make it: private vo
See the code explains.
public class A {
protected void test() throws Exception
{
System.out.println("in A");
}
}
public class B extends A
{
public void test() throws IOException
{
System.out.println("in B");
}
}
As
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