Skip to content

Instantly share code, notes, and snippets.

@kolunar
Last active April 24, 2017 23:01
Show Gist options
  • Save kolunar/2fa22246694f94959d2e1a87969cb267 to your computer and use it in GitHub Desktop.
Save kolunar/2fa22246694f94959d2e1a87969cb267 to your computer and use it in GitHub Desktop.
Java Programming :: Declarations and Access Control
Ref: http://www.indiabix.com/java-programming/declarations-and-access-control/
Access modifiers dictate which classes, not which instances, may access features.
Methods and variables are collectively known as members. Method and variable members are given access control in exactly the same way.
private
makes a member accessible only from within its own class
protected
makes a member accessible only to classes in the same package or subclass of the class
default
access is very similar to protected (make sure you spot the difference) default access makes a member accessible only to classes in the same package.
public
means that all other classes regardless of the package that they belong to, can access the member (assuming the class itself is visible)
final
makes it impossible to extend a class, when applied to a method it prevents a method from being overridden in a subclass, when applied to a variable it makes it impossible to reinitialise a variable once it has been initialised
abstract
declares a method that has not been implemented.
transient
indicates that a variable is not part of the persistent state of an object.
volatile
indicates that a thread must reconcile its working copy of the field with the master copy every time it accesses the variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment