Java overriding methods when creating new instance of a class

protected means (roughly) “available to sub-classes”. (See this table.) Since the new View(this) { ... } creates a subclass, it is possible to override the method within it.

In this case it doesn’t matter that you’re in a different package. (See the protected line and second column in this table.) The fact that the method is in a subclass is sufficient to “get access” to a protected method.


Potential follow-up question: What sense does it make, if I can’t call the method anyway?

All methods in Java are virtual. This means that whenever the View class performs a seemingly internal call to the onDraw method, this call will be dispatched to the overridden method.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)