简体   繁体   English

在java中为什么总是子类调用超类构造函数? 我想要内部流程

[英]In java why always child class call the super class constructor ? I want to the internal flow

I know how these stuff flow but I want to know when we make the object of child class it calls the parent class no arg constructor first. 我知道这些东西是如何流动但我想知道当我们创建子类的对象时它首先调用父类没有arg构造函数。 But i want to know the internal thing. 但我想知道内部的事情。

The parent class constructor needs to be called before the subclass constructor. 需要在子类构造函数之前调用父类构造函数。 This will ensure that if you call any methods on the parent class in your constructor, the parent class has already been set up correctly. 这将确保如果在构造函数中调用父类的任何方法,则父类已经正确设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM