search

Home  >  Q&A  >  body text

java - 请问下为何这个父类的方法输出不了?

父类中的test2方法没输出。。。

高洛峰高洛峰2803 days ago509

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:53:31

    You called the test() method in the constructor of the parent class, so that test() will be called when new is created. However, you did not call the test2() method, and there will definitely be no output. This is the basics of Java. in principle. You can write like this and there will be output.
    public Base{
    test();
    test2();
    }

    reply
    0
  • PHPz

    PHPz2017-04-18 10:53:31

    It would be better to directly copy the code for your question instead of taking screenshots.
    Because your code does not call the test2 method from beginning to end. It only calls the test method on line 5. You can write it on line 6test2();

    reply
    0
  • PHPz

    PHPz2017-04-18 10:53:31

    Why should it be output if there is no call? ? ?

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:53:31

    You have not called the test2 method of the parent class, so there will be no output.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:53:31

    test2() is not called in subclasses and categories, this really cannot be output

    reply
    0
  • Cancelreply