Sunday, August 10, 2008

Access Modifiers in java

1. private : Method or a variable can be accessible only from within its
own class.

2. protected : Method or a variable can be accessible only to classes in the same Package.

3. public : Class, method, or variable can be accessible from any other class in the same package or other packages.

Same class - Public, Protected, and Private
Same-package & subclass - Public, Protected
Same Package & non-sub classes - Public, Protected
Different package & Sub classes - Public, Protected
Different package & non- sub classes - Public

No comments:

private methods on Interface

  Private methods can be used on interface from java 9.   This will help in     Avoiding code duplication.     Ensuring code re-usab...