What are all the Java modifiers?? And how it works?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What are all the Java modifiers?? And how it works??

1st Apr 2017, 3:55 AM
Vignesh
Vignesh - avatar
3 Answers
+ 4
These are the main ones you'll need to know: public - all classes can access this. private - only this class can access this. protected - this, child classes, and package members can access this. then one other is package private - only package members have access. This is the default access for a class.
1st Apr 2017, 4:13 AM
Rrestoring faith
Rrestoring faith - avatar
+ 3
default: Variable/method can only be accessed by the class it's in, and the classes in the same package. public: Variable/method is visible to all classes outside the one it's declared in. private: Variable/method is only visible to the methods inside the class it's in. protected: Variable/method is accessible to the class it's in, all classes in the same package, and all subclasses.
1st Apr 2017, 4:14 AM
DaemonThread
DaemonThread - avatar
+ 1
Thanku for ur answers
1st Apr 2017, 4:18 AM
Vignesh
Vignesh - avatar