Java: Acess Modifiers

a thread...

(Cheatsheet Included)

What is an access modifier?

Access Modifiers are a way of providing limited visibility to methods, variables, classes.

Different access modifiers provide different visibility due to which our program because less prone to unwanted changes.
Java has four access modifiers, let's see each one by one

public:
It's the least restrictive access modifier when any class, method, or variable is defined as public then it is accessible from anywhere.
protected:
Protected methods & variables can be accessed within the same package and also accessible to all child classes.

default:
When no access modifier is specified then java treats it as default. With default methods & variables are accessible within the same package.
private:
It's the most restrictive access modifier, when given to any methods & variable it is only accessible within the same class.
Access Modifier Cheat Sheet:

More from Vikas Rajput

You May Also Like