• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regarding restriction of static methods and keyword super

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I have 3 puzzles
1.Why static methods were designed to be hidden but not overridden? because there's no practical need for "overriding static methods"? or the design choice is out of other kind of consideration?
2.Since static methods were bound at compile time, why they must also conform to the requirements in the respects of access modifier, return type and throws clause which i thought were a sort of contract between overriding methods and overridden methods. Pls. look at the following code, my puzzle is in the comments.

3.Why there's a restriction against keyword"super" appearing in a static context, consider above code, if i substitute " return super.f2(); " to the code of f1() in class B, it compiled cleanly, while if I do the same to the f2() in class B, it would complain "undefined variable :super ", why such restirction?
Any explanation is a great help, thanks in advance
James Du
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Since static methods were bound at compile time, why they must also conform to the requirements in the respects of access modifier, return type and throws clause which i thought were a sort of contract between overriding methods and overridden methods. "
Access modifier, return type and throws clause are certainly more than that. To use your contract metaphor, they are a contract with the entire rest of Java.
 
James Du
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,
Could you please give some more detailed explanation? a small segment of code would be more appreciated.
Regards
James
 
James Du
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still no response? come on, the question is not so hard!
Thanks
James
reply
    Bookmark Topic Watch Topic
  • New Topic