Use of 'super' keyword when accessing non-overridden superclass methods

后端 未结 8 2031
梦如初夏
梦如初夏 2021-01-02 12:38

I\'m trying to get the hang of inheritance in Java and have learnt that when overriding methods (and hiding fields) in sub classes, they can still be accessed from the super

相关标签:
8条回答
  • 2021-01-02 13:03

    It is advised that further changes to the inherited class will not necessitate addition of the super qualifier and also prevent errors if missed.

    0 讨论(0)
  • 2021-01-02 13:05

    You are doing the right way by not using the super keyword for accessing getTyreCost.

    But you should set your members private and only use the getter method.

    Using super keyword should be reserved for constructors and overridden methods which need to explicitly call the parent method.

    0 讨论(0)
提交回复
热议问题