• 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

Can static methods be overridden by static methods only?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I do a sample paper in web, I meet the question (true/false).
"Static methods can be overridden by static methods only."
I think this statement is true, however, the answer is wrong!
I want to know whether I am right or not!
thanks!
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephen
Static methods can not be overridden by non-static methods. Why do you say the answer is wrong?
The following code gives an error:


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static methods are not overridden. They belong to the class they were declared in. The concept of overriding applies to instance methods.
[This message has been edited by Jim Hall (edited December 12, 2001).]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look to the following example :
class TestClass
{
public static void methodA()
{
System.out.println("TestClass - in methodA");
}
}
public class TestClass1 extends TestClass
{
public static void methodA()
{
System.out.println("TestClass1 - in methodA");
}

public static void main(String args[])
{
methodA();
}
}
Conclusion : static method can be overriden by static method ONLY (same signature).
 
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
Just to clear things up, static method are NEVER overridden, but they are HIDDEN. Overriding is a concept that applies to instance methods only. Hiding, however, applies to class (static) methods. You can see that fact in the following section titles of the JLS:
JLS 8.4.6.1 Overriding (by Instance Methods)
JLS 8.4.6.2 Hiding (by Class Methods)
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
reply
    Bookmark Topic Watch Topic
  • New Topic