gpt4 book ai didi

java - 什么时候 Java 子例程不是方法?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:14:55 24 4
gpt4 key购买 nike

我在开始学习 Java 时遇到了这个问题,但我正在自上而下地学习,所以我想要一些方向:

这是在 Java tutorial 上相对较早:

As one final general note, you should be aware that subroutines in Java are often referred to as methods. Generally, the term "method" means a subroutine that is contained in a class or in an object. Since this is true of every subroutine in Java, every subroutine in Java is a method (with one very technical exception). The same is not true for other programming languages. Nevertheless, the term "method" is mostly used in the context of object-oriented programming, and until we start doing real object-oriented programming in Chapter 5, I will prefer to use the more general term, "subroutine." However, I should note that some people prefer to use the term "method" from the beginning.

我的问题是什么是“一个非常技术性的异常”。由于我正在学习多种堆栈技术,所以我想知道他所指的这个特定异常。它来自本教程: http://math.hws.edu/javanotes/c2/

最佳答案

引自chapter 5您链接到的教程:

Constructors are subroutines, but they are subroutines of a special type. They are certainly not instance methods, since they don't belong to objects. Since they are responsible for creating objects, they exist before any objects have been created. They are more like static member subroutines, but they are not and cannot be declared to be static. In fact, according to the Java language specification, they are technically not members of the class at all! In particular, constructors are not referred to as "methods."

关于java - 什么时候 Java 子例程不是方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9506416/

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