super() in Java

前端 未结 15 2240
逝去的感伤
逝去的感伤 2020-11-22 05:36

Is super() used to call the parent constructor? Please explain super().

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 06:05

    Calling the no-arguments super constructor is just a waste of screen space and programmer time. The compiler generates exactly the same code, whether you write it or not.

    class Explicit() {
        Explicit() {
            super();
        }
    }
    
    class Implicit {
        Implicit() {
        }
    }
    

提交回复
热议问题