How to assign super to a variable?

前端 未结 4 1907
长发绾君心
长发绾君心 2021-01-22 07:52

I\'d like to do the following:

public class Sub extends Super {
  public Sub(Super underlying) {
    if (underlying == null) {
      underlying = super; // this          


        
4条回答
  •  礼貌的吻别
    2021-01-22 08:51

    You have not understood the super keyword in java correctly. Refer the javadoc for super

    If your method overrides one of its superclass's methods, you can invoke the overridden method through the use of the keyword super. You can also use super to refer to a hidden field (although hiding fields is discouraged)

    Also, super() is used to call the parent class constructors.

提交回复
热议问题