"I Love Java Ranch"
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
"I Love Java Ranch"
"I Love Java Ranch"
saravanan ragunathan wrote:
but is there any reason to avoid static method from
inherit to subclass and overridding ?
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
"I Love Java Ranch"
saravanan ragunathan wrote:
still i have a doubt that why static method is not inherited..
i think its scope is only within the class in which it is declared(encapsulation)
is this right???
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Elchin Asgarli wrote:static + abstract = impossible
Seetharaman Venkatasamy wrote:you know nested interfaces are static implicitly!
![]()
Javin Paul wrote:
Where do you see the usage for interface inside interface, nested class does make sense if Inner or nested class is part of outer class but with the interface ............. , let me know if you come across any convincing scenario ?
Thanks
Javin
Javin Paul wrote:
Where do you see the usage for interface inside interface
Seetharaman Venkatasamy wrote:java.util.Map.Entry
"I Love Java Ranch"
saravanan ragunathan wrote:thanks gentlemans...
i understand that static method can't be overridden because
jvm takes only reference type not an real object they refers
so static methods are used for method hiding..
but same rules are applied to method hiding as in overridding
like (can't mention weaker privileges,can't mention
different return type)
why?
Not really, static methods are class-wide methods, and not instance-wide methods. First you have to think of difference between a class and an instance of that class, thus instance methods are methods for instances of a class, and static methods are for class itself. For example this is the reason you cannot call instance methods inside static methods, because in static methods there is no instance, it is class-wide.
"I Love Java Ranch"
saravanan ragunathan wrote:
my doubt is why they apply the same rules(can't mention
weaker privileges,can't mention different return types)
for method hiding as in method overridding...
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
If the rules of overriding are not followed- then it becomes method overloading and that will surely not participate in the kind of polymorphism we are talking when we consider overriding.
"I Love Java Ranch"
static + abstract = impossible