Method
MD. NADIMOZZAMAN PAPPO
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
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;
}
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
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
Why use Methods?
 Reusability, Portability
 Creating abstraction/ conceptual unit
 Methods can be called recursively
 Code readability
 To simplify
Method Example in C
Method Example in C++ & Java
Famous Methods- C,C++,Java
 Main function
 Constructor
 Abstract Methods
 Virtual Method

Method in oop

  • 1.
  • 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 declarea Method?  Return type  Method Name  Arguments  Method Body  Structure: return_type method_name(argument list){ instruction 1; …………. Method Body …………. Instruction n; }
  • 4.
    Method in ProceduralLanguages - 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
  • 7.
  • 8.
  • 9.
    Famous Methods- C,C++,Java Main function  Constructor  Abstract Methods  Virtual Method