Access Modifiers && Non-Access Modifiers
1. Public modifier
Public modifier provides universal access which means any public class, method or variable is accessible by everyone and everywhere. (You can access a public class both within the package and outside the package).
2.Default modifier
Default classes are accessible for classes in the same package, the default attributes, methods, constructors are accessible in the same package.
3.Private modifier
Private modified attributes, methods, constructors are accessible within the declared class.
4.Protected modifier
Protected attributes, methods, constructors are accessible in the same package and subclass outside of the package.
Non-access modifiers
1. Final Modifier
Final class cannot be inherited by other classes.
Final attributes, constructor, methods cannot be overridden or modified.
2. Abstract Modifier
An abstract class can be accessed by other abstract classes, and can be inherited from other classes.
Abstract defined attributes, methods can be only used in an abstract class.
3. Static Modifier
Static methods have access to class variables (static variables) without using the class’s object (instance).
Only static data may be accessed by a static method.
4. Transient Modifier
Transient attributes, methods are skipped when serializing the object containing items.
5.Synchronized Modifier
Synchronized methods can be accessed by one thread at a time.
6.Volatile Modifier
The value of an attribute is not cached thread-locally, and it is always read from the main memory.