Methods/Functions


  • 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:
  1.  name of the method
  2. type of object or primitive type the method returns
  3. a list of parameters 
  4. 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.
Previous
Next Post »