Say you have a package-scoped class:
class MyClass {
}
What is the difference between
class MyClass {
public f() { ... }
}
and
class MyClass {
protected f() { ... }
}
and
class MyClass {
f() { ... }
}
?
Since the class is package scoped, what will making the function public
or protected
do or add?
My reasoning for a package-scoped class:
- You can't use the class from outside the package since it is package scoped, so
public
has no additional effect. - Following the same reasoning,
protected
has no additional effect, as you must stay within the package anyway. - Therefore, only
private
has limiting effect as the other 3 modifiers (package,public
,protected
) are all the same.
Is this correct?
I don't see the difference between the modifies when the class is package scoped.