In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public
, protected
and private
, while making class
and interface
and dealing with inheritance?
Java – Differences Between Public, Protected, Package-Private, and Private Access Modifiers
access-modifiersjavaprivateprotectedpublic
Best Answer
The official tutorial may be of some use to you.
(same pkg)
(diff pkg)
public
protected
private
+ : accessible
blank : not accessible