2. What is Method?
A block of instructions/codes defined as -
On procedural language(C) – a Procedure
On OOP(C++,Java) – a procedure associated with an object class
OOP - Specifically an objects behavior
3. How to declare a Method?
Return type
Method Name
Arguments
Method Body
Structure:
return_type method_name(argument list){
instruction 1;
………….
Method Body
………….
Instruction n;
}
4. Method in Procedural Languages - C
They are called - Function
Return type – void, int, double etc
Function naming, Arguments, Method
Body
Receive parameters from caller
Perform the operations defined on
body
Return result or void to the caller
5. Method in OOP – C++,Java
Characteristics –
Access specifier, Modifier, Return-
type, Method name, Parameter list,
Prototyping, Method body
Acts like objects behavior
Also called Member Functions
Receive parameters from caller
Perform the operations defined on
body
Return result or void to the caller
6. Why use Methods?
Reusability, Portability
Creating abstraction/ conceptual unit
Methods can be called recursively
Code readability
To simplify