aspose file tools*
The moose likes Beginning Java and the fly likes can we override the static methods ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can we override the static methods ?" Watch "can we override the static methods ?" New topic
Author

can we override the static methods ?

Krishna prasad ambala
Greenhorn

Joined: Jul 03, 2008
Posts: 11
can we override the static methods ?
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Beforehand, what is your opinion? Can you just try the same in a sample program and update us with the result what you get?

It would be so nice and add more values to the knowledge!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
No, you can't.

I think this is one instance where we break the usual JavaRanch practice and give a straight answer.

No, you can't.

If you have two static methods with the same signature, they hide each other. See this FAQ, which is the same as I quoted on your other thread here. Although the compiler will happily accept hidden static methods, this can lead to a lot of confusion in use; you can have instance methods from one class and static methods from another expressed, so if you are tempted to hide anything: don't!
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
My understanding of this is that because static methods belong to the class they are not involved in polymorphism, and because they are not involved in polymorphism they cannot be considered as overriding one another. For example:



It prints "foo" because the compiler inserted a call to foo.snap() into the bytecode. It doesn't matter that a zoop object was created at runtime. In effect, no override occurred.


Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
can we override the static methods?
A quick search would have led you to these recent topics: Static Methods in an Interface, and then what linking mechanism uses java (early or late) which both discuss this in great detail.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we override the static methods ?