+ 1

why can't we call interface static method via subclass object??

we can call a static method of a class via its subclass object, but we can't call static method of an Interface via its subclass object. why? look at the code below: https://code.sololearn.com/c6eYYTUu8qiE

2nd Aug 2019, 7:53 PM
salar vahidi
salar vahidi - avatar
6 ответов
+ 2
Nope, it definitely doesn't work. Here's a code with interfaces, classes and static methods. Hope it's not confusing: https://code.sololearn.com/cnpkZ1DR2hHb/?ref=app
2nd Aug 2019, 8:47 PM
voja
voja - avatar
+ 2
because static method defined inside interface belongs to that interface, not to the class that implements it.
2nd Aug 2019, 7:59 PM
voja
voja - avatar
+ 2
Yes, you could do that, it's called method "hiding". But if you try to do that with interface and class that implements it, you will get error... I will try to write a code to demonstrate these stuff...
2nd Aug 2019, 8:12 PM
voja
voja - avatar
+ 1
static methods inside a superclass also belong to that superclass. don't they?? but they can be called via their subclass's objects
2nd Aug 2019, 8:05 PM
salar vahidi
salar vahidi - avatar
+ 1
thank you so much. so the same concept is not working on interfaces.interesting
2nd Aug 2019, 8:23 PM
salar vahidi
salar vahidi - avatar
+ 1
I got it now. that was really helpful thank you so much
3rd Aug 2019, 12:10 AM
salar vahidi
salar vahidi - avatar