Inheritance in Static Methods

后端 未结 5 433
南笙
南笙 2020-12-01 18:51

Why does the below code print \"Main\"?

public class Main
{
    public static void method()
    {
        System.out.println(\"Main\");
    }

    public sta         


        
5条回答
  •  自闭症患者
    2020-12-01 19:39

    static methods are statically binded with their class name because m is type of Main class then after compilation it would look like as following Main.method(); after compilation of your class run the following command javap -c Main u can see the jvm assembly code for Main class and u would see following m.method //invoke static invoke static ,invoke special tells that static binding invoke special,invoke interface tells that dynamic binding

提交回复
热议问题