问题
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?
- A method is on an object.
- A function is independent of an object.
- For Java, there are only methods.
- 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