• 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

Static methods can't be overridden?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can static methods be overridden? I am confused. It's said "static methods can't be overriden!" on K&B 1.4 book page 103. But when I tried the following code in my compiler, it worked well. So, anyone can explain this to me? Thank you very much.

public class Child extends Parent {

public static void method1()
{
System.out.println("method12");
}
public static void main(String[] args) {
method1();
Parent.method1();
}
}

class Parent{
public static void method1()
{
System.out.println("method1");
}
}
[ November 01, 2005: Message edited by: Wendy Lum ]
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

After you run this programmer , you will know the reson.
"Static methods can't be overridden " , that's means the child static methods cann't overridden the parent methods when programmer
runing. the child always use parent static methods when you use it's static method.
 
Wendy Lum
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Leoo. I got it.
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of couse. It' can redefine but it's not overridding, instead of that it's called "hiding".
That mean the polymorpism don't apply.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic