Why can't I refer to an instance method while explicitly invoking a constructor?

后端 未结 6 1615
青春惊慌失措
青春惊慌失措 2020-12-01 08:53

Does anyone know why you can reference a static method in the first line of the constructor using this() or super(), but not a non-sta

6条回答
  •  -上瘾入骨i
    2020-12-01 09:37

    If a method is non-static then you must call it on an object.

    In the second example you would need to create an object of class TestNotWorking and call getAFromB on that object.

    Something like:

    object = new TestNotWorking();
    object.getAFromB(bParam);
    

提交回复
热议问题