Forums Register Login

static problem

+Pie Number of slices to send: Send
why can't we declare abstract methods as static...?i know that we can't ...but don't know the exact reason for it...please help!
+Pie Number of slices to send: Send
Static methods can't be overriden, so it really doesn't make sense to declare a static method as abstract, as there is no way to define it by subclassing.

Henry
+Pie Number of slices to send: Send
Well, in short, because in Java, abstract method implementations are looked up at runtime by checking the exact type of the object the method is called on. Since static methods are called without reference to an object -- i.e., you can call them as ClassName.methodName(), with no object involved -- there would be no way to figure out which implementation you mean. Of course you could work out a system for doing this, but Java's creators wanted the language to stay simple, with relatively few rules for understanding its behavior.
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 796 times.
Similar Threads
using static method in polymorphism
Can you use static sections? (NOT static variables, this is diff)
Abstract Methods and Classes
question from master exam
static in inner class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:11:27.