The following code demonstrates that the subclass named SubClass
has a direct access to a final static synchronized method named staticMethod. There is no need to associate it with its class name.
package synchronizedpkg;
class SuperClass
{
public final static synchronized void staticMethod()
{
System.out.println("Method called.");
}
}
final class SubClass extends SuperClass
{
public void woof()
{
staticMethod();
}
}
final public class Main
{
public static void main(String[] args)
{
new SubClass().woof();
}
}
This is somewhat confusing in terms of inheritance because a final method can not be inherited and consequently should not directly be accessed by it's subclasses. How does a final static method as shown above have a direct access from its child class?