+ 3
Methods are 'functions' in java ?
we have functions in C,C++,Python.. but we have methods in java..correct?
2 Antworten
+ 12
A method is a function that belongs to a class. So all methods are functions, but not all functions are methods.
Java is fully OOP and requires that all code is written inside a class, so therefore all (non-static) functions in Java are methods.
C, C++, and Python, however, don't require use of classes, so only functions inside classes are methods.
+ 2
methods and functions are interchangable terminology. Although historically functions in c, c++, python means free flowing functions i.e not tied to class (c++, python) or say global or local functions. when function appears in classes they are called methods be it java, python or c++.