This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes All about static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "All about static methods" Watch "All about static methods" New topic
Author

All about static methods

Anuj Singh
Ranch Hand

Joined: May 04, 2007
Posts: 47
Why cant we override static methods?


SJCP 1.5 with 93%.Preparing for WCD
Samrat Som
Ranch Hand

Joined: Feb 04, 2009
Posts: 40
hey this link will help you better to understand than my explanation
webpage


SCJP 1.6
SCWCD 1.5 (Preparing...)
Antany Vasanth
Ranch Hand

Joined: Jan 28, 2009
Posts: 43
Hi Anuj,

Static methods or variables are class level not instance level.

You can directly access static methods without creating object for that class.

Static methods can't be overridden but can be re-defined in its subclass.

Consider the following example



Hope you understand it.

Regards,
Antany
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Please read http://faq.javaranch.com/java/OverridingVsHiding as well.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
very nice explanation.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Anuj Singh
Ranch Hand

Joined: May 04, 2007
Posts: 47
Hi Antany,
A lovely explanation!Thanks a ton!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
Samrat Som wrote:hey this link will help you better to understand than my explanation
webpage
But that link uses C# rather than Java, so only the Strategy Pattern solution will work for us.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: All about static methods
 
Similar Threads
Static methods can be overridden by static methods only?
static and non-static synchronized methods
method overriding
Inheritance of all members
What is the logic behind calls like JOptionPane.method()