- Methods are functions that operate on instances of classes in which they are defined.
- Objects can communicate with each other using methods and can call methods in other classes.
- A method consists of the operations that an object performs when it receives message.Methods have mechanisms that have access to and can change the state of an object
- Method definition has four parts. They are:
- name of the method
- type of object or primitive type the method returns
- a list of parameters
- body of the method.
- A method’s signature is a combination of the first three parts mentioned above.
type methodname1(parameter-list)
{
//body of method
}
When we use return type void, the function does not return a value.