Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Modifiers

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why can't a abstract method also be declared as
static?
Why is
static abstract void k12();
incorrect ?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because static methods can't be overriden and abstract methods must be overridden.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul:
I always wanted to find out if there is anything construct in Java that will allow polymorhism for static method methods?
Thanks
Barkat
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static methods do not participate in polymorphism. They can't because they are inlined at compile time.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use the static modifier with a method's prototype. When declaring an abstract method it's not implemented yet.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sgopalan,
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.
PS: Quote from the naming policy:


For your publicly displayed name, use a first name, a space, and a last name. Obviously fictitious names or improperly formatted names may be locked out.

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Static methods do not participate in polymorphism. They can't because they are inlined at compile time.


Hey this is new to me. I only thought final methods were inlined at compile time. What other kinds of method can be inlined?
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private methods are also inlined. Making a private method final is redundant.
 
Bishal P
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so bottomline is that any method that cannot be overridden can be inlined. Cool, thats easy to remember.
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's even more interesting is that some methods are inlined at run time. See this thread:
https://coderanch.com/t/201812/Performance/java/Making-everything-compiler-allows-final
The bottom line is that any method that can possibly be inlined will end up being inlined as soon as possible, either at compile time or runtime.
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, will the methods be inlined regardless of the size of the method? wouldn't that be an overhead? If a method that is eligible for inlining has a huge size, and also invoked a lot of times from a single method, wouldn't inlining be a dis-advantage? (because i read somewhere that the maximum size of a single method is ~64k bytes)
I think the C/C++ compilers take these details into consideration before inlining. Any links on this topic?
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vin Kris:
(because i read somewhere that the maximum size of a single method is ~64k bytes)

I am sure Java takes this into account but... a method in Java > 64k bytes!!! Was it written by a COBOL programmer?
(This is not meant as a swipe at COBOL programmers. It is simply the case that COBOL programmers generally write large scale procedural top down programs.)
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic