Java – internal classes that use the main method cannot be compiled

abstract class Manager {
abstract class Manager {

    static void test() {
        System.out.println(12);
    }

    class Manager1 {
        public static void main(String args[]) {
            System.out.println(Manager.test());
        }
     }
}

It produces compile - time errors Can abstract classes use static methods of void type?

Solution

Non static inner classes cannot have static methods - only top-level and static classes can (according to JLS § 8.1.3)

In addition:

System.out.println(Manager.test());

Manager. Test() is invalid: you cannot print it out

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>