Static methods and their overriding

前端 未结 5 1754
挽巷
挽巷 2020-12-03 06:36

Java doesn\'t allow overriding of static methods but,

class stat13
{
    static void show()
    {
        System.out.println(\"Static in base\");
    }
    p         


        
5条回答
  •  广开言路
    2020-12-03 06:45

    Overriding happens when a child-class provides it's own implementation for a method such that the child-class instance will be invoked. The operative word here is - instance.

    Static methods are invoked in the context of the class e.g.

    stat13.show(...);
    

    OR

    next.show(...);
    

    FWIW, your sample code is not an example of overriding.

提交回复
热议问题