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.
@laurspilca
4 жыл бұрын
Hi yes. Certification questions exams and sometimes interview questions (even if I don't agree with those that ask trivia questions in the interviews... most of the times, not knowing to answer a trivia question doesn't mean you don't know the language.)
@MrEuugen
2 жыл бұрын
best explanation! thank you
@robertgherlan7195
4 жыл бұрын
a1.m() is replaced at compile time with A.m() and for that the actual type of a1 doesn't matter.
@laurspilca
4 жыл бұрын
Code on GitHub: github.com/lspil/youtubechannel/tree/master/redefining_static_methods
@radu8618
4 жыл бұрын
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
@laurspilca
4 жыл бұрын
Correct! :)
@AliHassan-bz9sk
10 ай бұрын
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?
@laurspilca
10 ай бұрын
Hei. I guess that makes sense. A static method is linked to the type while a non-static one is instance behavior. They live in two different worlds.
@AliHassan-bz9sk
10 ай бұрын
@@laurspilca thanks 👍
@AliHassan-bz9sk
10 ай бұрын
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?
@laurspilca
10 ай бұрын
Hey. Interesting question. I don't know why that limitation was added to the language.
Пікірлер: 13