Issue
Can classes in java have any other access specifier than public ? Can we save our file with that classname which has specifier other than public ?
Solution
Access modifiers in java – explain.
I) Class level access modifiers (java classes only)
Only two access modifiers is allowed,
public
and no modifierIf a class is ‘
public
’, then it CAN be accessed from ANYWHERE.If a class has ‘no modifier’, then it CAN ONLY be accessed from ’same package’.
II) Member level access modifiers (java variables and java methods)
All the four
public
,private
,protected
and no modifier is allowed.
public
and no modifier – the same way as used in class level.
private
– members CAN ONLY access.
protected
– CAN be accessed from ’same package’ and a subclass existing in any package can access.
source: http://javapapers.com/core-java/access-modifiers-in-java-explain
Answered By - XpiritO
Answer Checked By - Willingham (JavaFixing Volunteer)