aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static methods" Watch "Static methods" New topic
Author

Static methods

Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
SCJP by Sierra and Bates say that static methods can't be overridden but they can be redefined.can someone please explain using an example.i couldn't understand.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


Static methods cannot be overridden because they simply would not be visible to derived classes (sub-classes).
If you define a method with the same signature in a sub-class you would be declaring a new/different method.
This is what K&B mean by "redefining".

Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
I think they are not visible to subclasses because it is told that they are not linked with any instances of a class but then why can we access static methods using object reference variables.
ravi suthar
Greenhorn

Joined: Apr 22, 2012
Posts: 17

static methods cannot be override in subclass but you can define static methods in subclasses also with the same name and same method signature as defined in superclass. this is called method hiding.
ravi suthar
Greenhorn

Joined: Apr 22, 2012
Posts: 17

static methods cannot be override in subclass but you can define static methods in subclasses also with the same name and same method signature as defined in superclass. this is called method hiding.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


This link explains this is detail:

http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

If you are still not sure about the difference between overriding and hiding, execute the below section of code and analyze the behavior of hiding and overriding by cheking the output.



The output would be as mentioned below -


Regards
Salil Verma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static methods