Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes can we cal ststic methods with super keyword? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can we cal ststic methods with super keyword?" Watch "can we cal ststic methods with super keyword?" New topic
Author

can we cal ststic methods with super keyword?

Krishna prasad ambala
Greenhorn

Joined: Jul 03, 2008
Posts: 11
can we cal ststic methods with super keyword?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Krishna prasad ambala:
can we cal ststic methods with super keyword?


yes..you can do that.
--------------------------------
but inside static method ,you can not use super key word
--------------------------------
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38046
    
  22
The correct answer is, yes and no.
The compiler will happily let you call the static method from the superclass with the super keyword, but it is not necessary.That should compile and run nicely without the super keyword. If you need the super keyword, that suggests you have hidden the static method with another with the same signature in the subclass. This is bad style, since it can lead to great confusion about which method you are calling, and probably also means your subclass IS-NOT-A superclass. As Joshua Bloch will tell you , in Effective Java (as reviewed by one C Ritchie in Bunkhouse Books here on JavaRanch), avoid hiding static members in subclasses. You should probably also avoid hiding instance fields by having any fields of the same name. The only thing one should duplicate in a subclass is instance methods, and that is called overriding. We have an FAQ about overriding and hiding.
 
Consider Paul's rocket mass heater.
 
subject: can we cal ststic methods with super keyword?
 
Similar Threads
compiler error
Super Inside the Static
can we override the static methods ?
order of operations static fields, init statments, constuctors and inheritance
Super