Typefully

Java: Access Modifier

Avatar

Share

 • 

4 years ago

 • 

View on X

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:
Any Questions, Feedback, or Suggestion? I am waiting for you in the comment section below. You might also like my other thread on Java: twitter.com/vikasrajputin/status/1519148879693811712
Thanks for reading! Hi, I'm Vikas Every Mon, Wed & Fri I write threads on Java, Javascript & Fullstack Development. Happy Coding!
Avatar

Vikas Rajput

@vikasrajputin

Sr. Backend Engineer. Simplifying Backend and sharing what I learn along the way. Building Gujarat's biggest java community at @juggujarat