I have a class which has a method whose access specifier by default is public. Now, I would like to extend this class in a subclass and I want to override this method to hav
Because you alter the order of access privileges , so you got error
correct order is:==> private to default to protected to public
*in your case you goes default ==> private whenever you goes in wrong order ,it result is error
Right order of access privilege is--
`class SuperClass{
void foo(){
System.out.print("SuperClass");
}
class SubClass extends{
//--default to default--//
void foo(){
System.out.print("SubClass");
}
//--default to protected--//
protected void foo(){
System.out.print("SubClass");
//--default to public //
public void foo(){
System.out.print("SubClass");
}`
**you make sure to preserve correct order while overriding **