[QUESTION] Calls and redefinition of static vs non-static methods

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

This nuance of the language is good to know. I agree that this likely does not occur much (nor should it) in production code but if one sees it, he will know how to interpret. And it avoids incorrectly answering an interview question.

thethreestorms
Автор

a1.m() is replaced at compile time with A.m() and for that the actual type of a1 doesn't matter.

robertgherlan
Автор

So, one of the main ideas from the video is:
When we talk about class or static methods, the method according to the type of reference is called, not according to the object being referred
When we talk about instance (or non-static) methods, the method is called according to the type of object being referred, not according to the type of reference

radu
Автор

I have another concern which I faced today. Suppose a class has a static method that one of its subclasses decides to hide by redefining. Now, I'm wondering why a non-static method can't actually be used to hide a static method. Only static to static redefining is successful -- neither static to non-static redefining nor vice versa But why?

AliHassan-bzsk
Автор

Thanks, I just wanna ask a silly question 😅that is why re-definition of static methods doesn't work for interface. Are static methods not inherited in case of interface?

AliHassan-bzsk