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

标签 java methods subroutine

我在开始学习 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/

相关文章:

Java - Try/catch 方法问题

ruby - 为什么会出现未初始化常量 Stuff::HTTPParty 错误?

java - Oracle/Java 应用,推荐架构

java - 通过java获取neo4j中具有相同索引值的所有节点?

java - 为什么 assertEquals(new int[]{1}, new int[]{1}) 会导致失败?

multithreading - 如何使用线程代替 perl/pdl 中的子例程循环

linux - Perl 检查子目录并更改所有权

java - 改进 JFrame 和 JPanel 之间的通信

java - 学校作业多维数组麻烦

C 字符数组打印,使用子程序