Issue
I have noticed that if I don't write public
before a class it works same as like a public class
. I can't understand why so? It should show an error when I don't declare a class as public
, private
or protected
. But it works fine. What is the reason?
Solution
public
, protected
and private
are access modifiers. Public means that the subject may be accessed by any class, protected by subclass, private by the class itself, no modifier means "package protected", so the subject may be accessed by classes from the same package.
Subject is class, method, member variable.
Answered By - AlexR
Answer Checked By - Candace Johnson (JavaFixing Volunteer)