• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can we cal ststic methods with super keyword?

 
Krishna prasad ambala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we cal ststic methods with super keyword?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic