This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding / hiding a final static method  RSS feed

 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A{

public static final void m() {...}

}

class B extends A{
public static final void m(){ ... } // a compilation error
}

According to Oracle Java tutorial web site, an instance method in the child class with the same signature is called overriding method and a static method in the child class with the same signature is called hiding method.

It may be out of the scope of this exam. Why can't we hide a final static method in the parent class ? Why is there a compilation error in class B.

Final method cannot be overriden. Why can't we hide a static final method?

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A final method is such that you cant change its definetion in any way, even if it is static. Thats why compiler gives error when you try to hide it in child class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!