This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding / hiding a final static method

 
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