[英]Inner class with main method doesn't compile
abstract class Manager {
static void test() {
System.out.println(12);
}
class Manager1 {
public static void main(String args[]) {
System.out.println(Manager.test());
}
}
}
It's producing a compile time error. 它产生编译时错误。 Can an abstract class have a
static
method with void
type? 抽象类可以使用
void
类型的static
方法吗?
Non-static inner classes cannot have static
methods - only top-level and static classes can (as per JLS §8.1.3 ). 非静态内部类不能有
static
方法 - 只有顶级和静态类可以(根据JLS§8.1.3 )。
Furthermore: 此外:
System.out.println(Manager.test());
Manager.test()
is void: you can't print that. Manager.test()
无效:你无法打印出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.