Why functions are called methods in java? [duplicate]

久未见 提交于 2019-12-24 03:37:16

问题


Why functions are called methods in java. I am not asking the difference between the two. Why Java community choose to name them methods. Is there any concrete reason behind this decision or it's just a name? When i think of literal meaning as far as i could think function is related to internal working of some machine. Method is a way of working to achieve a goal(mathematical solution) or may be method is a way of implementing an Object. Is that where it came from or i just missed the real picture?


回答1:


It's not in Java, it's an OOP name.

In sort, it defines part of the behavior of an instance of an object, not a general operation.




回答2:


Every language has it's own syntax to differentiate from others. As for your question

Functions existence is independent.

Methods do not as they are created within the class.




回答3:


Why functions are called methods in java?

  1. A method is on an object.
  2. A function is independent of an object.
  3. For Java, there are only methods.
  4. For C, there are only functions.

For C++ it would depend on whether or not you're in a class.

In languages such as C++, functions are bits of code that will perform a particular action - but are not associated with an object. functions that are to do with an object are called methods. in java all functions are methods as they are all to do with objects.



来源:https://stackoverflow.com/questions/22913321/why-functions-are-called-methods-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!