在什么情况下可以定义static 方法?


  只有在顶层类中定义,或者在静态内部类中定义,看下面的例子

public class Test {
 static void t(){}
 class T2{
  //!错误,The method a cannot be declared static;
  //static methods can only be declared in a static or top level type
  //static void a(){}
 }

 static class T3{
  static void a(){}
 }
}
原文地址:https://www.cnblogs.com/dkblog/p/1980879.html