File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding / hiding a final static method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding / hiding a final static method" Watch "overriding / hiding a final static method" New topic
Author

overriding / hiding a final static method

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
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

Joined: Oct 15, 2011
Posts: 249

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.


Astha - OCPJP 6 (90%)
 
Don't get me started about those stupid light bulbs.
 
subject: overriding / hiding a final static method