When we override a method in a subclass, we call the superclass method within this method, for example:
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
width = w ;
height = h ;
Log.d(TAG, "onSizeChanged: width " + width + ", height "+ height);
super.onSizeChanged(w, h, oldw, oldh);
}
So why do we need to call super.onSizeChanged()?
I delete the line super.onSizeChanged(), and the result is the same as with it.
Or the same in onCreate method, we call super.onCreate().
There are certain methods that do essential things, such as onCreate and onPause methods of activity. If you override them without calling the super method, those things won’t happen, and the activity won’t function as it should. In other cases (usually when you implement an interface) there is no implementation that you override, only declaration and therefore there is no need to call the super method.
One more thing, sometimes you override a method and your purpose is to change the behavior of the original method, not to extend it. In those cases you should not call thesuper method. An example for that is the paint method of swing components.