Skip to content

Instantly share code, notes, and snippets.

@browny
Created July 29, 2011 05:16
Show Gist options
  • Save browny/1113176 to your computer and use it in GitHub Desktop.
Save browny/1113176 to your computer and use it in GitHub Desktop.
[Java] Access modifier of an overriding method
class Base {
private int privMethod() { return 1; }
int packMethod() { return 1; }
protected int protMethod() { return 1; }
public int pubMethod() { return 1; }
}
class Derived extends Base {
//@Override
//private int pubMethod() { return 0; } // Error
//int pubMethod() { return 0; } // Error
//protected int pubMethod() { return 0; } // Error
//public int pubMethod() { return 0; } // OK
//@Override
//private int protMethod() { return 0; } // Error
//int protMethod() { return 0; } // Error
//protected int protMethod() { return 0; } // OK
//public int protMethod() { return 0; } // OK
//@Override
//private int packMethod() { return 0; } // Error
//int packMethod() { return 0; } // OK
//protected int packMethod() { return 0; } // OK
//public int packMethod() { return 0; } // OK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment