class X
{
final static void show()
{
System.out.println("Show");
}
}
class Y extends X
{
public static void main(String s[])
{
new Y().show();
}
}
Where and how is memory allocated to final static methods, and how are they accessed?
When you make a static method final, its hidden in the inheriting class. You can find a decent explanation at http://www.coderanch.com/how-to/java/OverridingVsHiding
When you create a method with the modifier "final" you are modifying that method so that it cannot be overridden or hidden.
So if you were for some reason to create another class that were to extend your class X (which is known as inheritance), you would not be allowed to modify, or override your show() method. Furthermore, any other class would be able to access that method.
If you want a more in depth explanation, I suggest reading the Java API: https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.