TYPES OF METHODS
** Actually , what these method prototypes are?.. Well!! don’t worry me and my blog is there to explain you each and every thing .
- Method prototypes are nothing but the types of methods we generally use while programming . That is, at what instance of time what type of method should be used to maintain good programming .
- First to know about method prototypes, we should be first aware of arguments and return values. Arguments are nothing but the formal parameters which are defined inside the parenthesis of the method declaring . And return values are nothing but the returning values to the main(0 method .
- Method prototypes are classified into three types , based on the arguments list and return types .
1. Method without arguments , without return values .
2. Methods with arguments , without return values .
3. Method with arguments , with return values .
Now , too much theory is not good for programming . we will see the three types in one program very clearly .
PROGRAM 1 :
PROGRAM 2 :
** THE ABOVE METHODS WHICH WE ARE DEFINED, THOSE ALL METHODS ARE CALLED AS ‘INSTANCE METHODS’ . WHICH CAN BE REFERRED BY USING OBJECT .
**DIFFERENCE BETWEEN FORMAL ARGUMENTS AND ACTUAL ARGUMENTS
- Formal arguments are nothing but the parameters which are defined in the function(method).
- Formal arguments acts as local variables within the class.
- Formal arguments are copies of the actual arguments .
- Actual arguments are nothing but the arguments which we are passing at the time of invokation of that method .
- Actual arguments may contain values , variables , expressions .
- The return type of both actual and formal parameters must be same , but not locations
**IMPORTANT QUESTION :
?? When to define a function (method) with return () and when to define a function (method) without a return() ?
ANS . The value which is no more longer in use through out the program then there is no need to define a return type and return value .But when the values of that method have further in use in the program then you should store that value by returning to the main() method by returning some value with the help of return type .