Protected and “package-private” visibility when inheriting from class in different package
I’m kind of new to visibility and want to really internilize these concepts.
I’ve learnt that “package-private”, the default visibility in Java, allows us to see fields from classes in the same package; and that protected, apart from implying package visibility,
also allows us, from class Child
in otherPackage
, get fields declared in Parent
class in thisPackage
,
as long as we are asking for them to an instance of class Child
or a descendant.