简体   繁体   English

在主类中调用重写的方法

[英]Call an overridden method in my main class

My code is like this... but there seems to be a problem when I call the overridden method createHome(). 我的代码是这样的……但是当我调用重写的方法createHome()时似乎出现了问题。 Here is a sample code: 这是一个示例代码:

public class Test extends SweetHome3D {
  public static void main(String [] args) {
    new Test().init(args);
    ***createHome();***
  }

  @Override
  public Home createHome() {
    Home home = super.createHome();
    // Modify home as you wish here
    return home;
  }
}

I take it that code didn't compile? 我认为代码没有编译? You are calling createHome() as if it's a static method. 您正在调用createHome() ,就好像它是静态方法一样。

public static void main(String [] args) {
  Test test = new Test();
  test.init(args);
  test.createHome();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM