A method is a collection of set of statements, and methods are used to break a complex program into small parts- these small parts also known asprocedure, modules, or subprogram.
Methods are used to
Why we need Methods -
So if you want to perform that particular job then you can simply call the method and leave the rest to it.
For example, say you have problems in your television set. So in this case you will call the TV mechanic and rest assured that he will fix the problem. TV mechanic can be thought of as a method who has entire set of code written in him to fix any problem in television.
Same television mechanic can be called by different person.
Advantage of Methods
Class Methods are catogarised into four(4) Types -
1. Non-Parameterized with non-Value returning
When a method does not take any argument, or parameter within parenthesis, and does not returns any value is called Non-Parameterized with non-Value returning method.
Example - Create a method that read a number from user and display code of no.
2. Parameterized with non-value returning
A method that takes a variable as argument or parameter, but does not return any value called Parameterized with non-value returning method.
Example - we will modify the previous example
3. Parameterized with value returning
A method that takes a variable as argument or parameter, but does return a value called Parameterized with value returning method.
Example -modifying in previous example -
4.Non - Parameterized with value returning
A method that does not takes any variable as argument or parameter, but does return a value called Parameterized with value returning method.