aspose file tools
The moose likes Beginning Java and the fly likes static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "static methods" Watch "static methods" New topic
Author

static methods

Suri Babs
Ranch Hand

Joined: Mar 27, 2003
Posts: 50
Can i override static methods (y/n). Explanation please in either case.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
You can override static methods. Look at the following code:

The thing is, static methods do not participate in polymorphism. Note that when you declare:

it prints "Super," even though the instance is of type "Sub"


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can not override static methods. Static methods are hidden not overridden.
JLS 8.4.6.2 If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class. A compile-time error occurs if a static method hides an instance method.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: static methods
 
Similar Threads
static and non-static synchronized methods
What is the logic behind calls like JOptionPane.method()
method overriding
Static methods can be overridden by static methods only?
Inheritance of all members