RT。java能办到吗?或者有没有其他办法?

解决方案 »

  1.   


    父类中的static方法是不可以重写的
      

  2.   


    public abstract class Test {
    public static void f()  {
    throw new RuntimeException("You must override this static method.");
    }

    public static void main(String[] args) {
    A.f();
    B.f();
    }
    }class A extends Test {
    public static void f() {
    System.out.println("This is a method of class A.");
    }
    }class B extends Test {
    }
      

  3.   

    static方法没有多台的概念,不能被重写,只会被隐藏
      

  4.   

    不懂你的意思。我的代码只在main函数中引用了派生类。貌似main函数在哪里都可以吧。我只不过是为了方便才写到基类里。