Mehrdad Faraji
Mehrdad Faraji

Reputation: 3914

What is distinction between subclass of superclass in same package and different package?

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?

Upvotes: 1

Views: 166

Answers (1)

Chris
Chris

Reputation: 7853

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.

Upvotes: 2

Related Questions