Inheritance in Static Methods

后端 未结 5 441
南笙
南笙 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:51

    Eclipse gives me this sort of warning when I try to do this sort of thing:

    The static method XXX() from the type XXX should be accessed in a static way

    Static methods do not take part in inheritance. The variable is of type Main, so the compiler resolved your function call to Main.method().

    For added fun, try setting m to null.

提交回复
热议问题