A method is a block of code that performs a task and is associated with a class or an object. It is related to the non-object-oriented concepts of functions and procedures.
A method is a code block that contains a series of statements. A program causes the statements to be executed by calling the method and specifying any required method arguments.
In object-oriented programming, a method is a subroutine (or procedure) associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time.
Methods have the special property that at runtime, they have access to data stored in an instance of the class (or class instance or class object or object) they are associated with and are thereby able to control the state of the instance.
The association between class and method is called binding. A method associated with a class is said to be bound to the class. Methods can be bound to a class at compile time (static binding) or to an object at runtime (dynamic binding).
Common features
They have few things in common:
- They may take some parameters / arguments for their processing.
- They may have a return-value, that returns some value to the calling method.
- The concept of static-binding and dynamic-binding is also associated with methods.
References
Also see: