gpt4 book ai didi

java - 谁提供了Java中的默认构造函数?编译器还是 JVM?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:52:17 24 4
gpt4 key购买 nike

构造函数是在运行时添加的还是编译时添加的?(我猜是编译时)。请在 JVM 架构级别进行一些深入的解释。

我阅读了各种文章..一些说编译器..还有一些说 JVM。我想非常确定(证据会有很大帮助)。

抱歉,如果这个问题很愚蠢(我还在消化术语)!!!

提前致谢。

最佳答案

来自 Oracle 的 Java 教程:https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor will call the no-argument constructor of the superclass. In this situation, the compiler will complain if the superclass doesn't have a no-argument constructor so you must verify that it does. If your class has no explicit superclass, then it has an implicit superclass of Object, which does have a no-argument constructor.

关于java - 谁提供了Java中的默认构造函数?编译器还是 JVM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43744397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com