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

Static methods question

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wrote following code to see if this statement is true:
Static methods can not be overridden.


I think line 1 is an overriding method not a redefined method. To proof it, i changed line 1 to:
static synchronized void go(final int� a) throws Exception
Then compiler starts to complain...

Static methods can not be overridden,REALLY?
[ May 30, 2006: Message edited by: Xinhua Gu ]
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot override a method marked static. K&B pgno 103
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see this thread
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=032787
 
Xinhua Gu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the answer:
http://faq.javaranch.com/view?OverridingVsHiding
Thank you very much!
 
Xinhua Gu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually, i donot like the "hiding" explanation from FAQ.

In my preceding codes, defining static method in subclass follow all the rules for legal overrides at compiler level e.g. it can not contain more strict visibility or it can not throw an Exception arbitrarily. Thus, it is NOT a redefined method. (in K&B page 147 says it IS redefined)

It JUST does not work for run-time polymorphism.

So, the bottom line is how to understand "can not be overridden".
For final method, "can not be overridden" means a compile error
Here, for static method it means "does not work for run time polymorphism"

Am i right?

Thanks for all the help.
[ May 31, 2006: Message edited by: Xinhua Gu ]
 
What's that smell? Hey, sniff this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic