Methods are 'functions' in java ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Methods are 'functions' in java ?

we have functions in C,C++,Python.. but we have methods in java..correct?

11th Jun 2017, 6:14 AM
suryapoojary
suryapoojary - avatar
2 Answers
+ 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.
11th Jun 2017, 6:32 AM
Tamra
Tamra - avatar
+ 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++.
11th Jun 2017, 6:38 AM
NeutronStar
NeutronStar - avatar