Java Modifiers
A Java modifier is used to control the visibility of an interface, class, method, or a variable. Modifiers in Java can be either access modifiers or non-access modifiers. Using access modifiers, you can control which classes, methods, or variables are visible. These keywords can be used to restrict access to classes and members, either from within the same package or from other packages.
Access Modifiers:
public:The code is accessible for all classesprotected:The code is accessible in the same package and subclasses.default:The code is only accessible in the same package. This is used when you don’t specify a modifier.private:The code is only accessible within the declared class
Get Bora Fazli’s stories in your inbox
Join Medium for free to get updates from this writer.
Non-Access Modifiers:
final:Attributes and methods cannot be overridden/modifiedstatic:Attributes and methods belongs to the class, rather than an objectabstract:Can only be used in an abstract class, and can only be used on methods.transient:Attributes and methods are skipped when serializing the object containing themsynchronized:Methods can only be accessed by one thread at a timevolatile:The value of an attribute is not cached thread-locally, and is always read from the "main memory"






