1
votes

What is difference between this two sentence :

AA- a subclass within the same package as the instance's superclass can override any superclass method that is not declared private or final.

BB- a subclass in a different package can only override the non-final methods declared public or protected.

I believe each method can be overriden from it's superclass if it is not final
in java private methods are "automatically final, and hidden from the derived class"

in java any non-static methods can be public , protected or private

So from sentence AA I conclude that only public and protected superclass's methods can be overriden
and the same from sentenceBB

So I confused what is the distinction between 2 sentences?

1
AA can override package private methods, whereas BB can't.SBI
You forgot the default modifieruser1933888

1 Answers

2
votes

The Sentences from your source are a bit unclear actually.

Sentence A also includes the default declared methods. This is also referred to as "package private". This happens if you just ommit the access modifier on your method.

Classes outside of the package won't be able to override them.