-3

What is the difference between function and method ? Can any one say with suitable example say what are the differences? Where we say some routines are called function and where it is called method?

RBT
  • 24,161
  • 21
  • 159
  • 240
user3251646
  • 278
  • 4
  • 15

1 Answers1

0

Function or a method is a named callable piece of code which performs some operations and optionally returns a value.

In c language the term function is used. Java & C# people call these methods (and a function in this case is defined within a class/object).

A C++ programmer might call it a function or sometimes method (depending on if they are writing procedural style c++ code or are doing object oriented way of c++).

You call a function by just calling it's name like result = mySum(num1, num2); You would call a method by referencing its object first like

result = MyCalc.mySum(num1,num2);

Check the link in CubanAzucy's answer. It is already discussed in great detail on Stack Overflow.

Abdullah Leghari
  • 2,332
  • 3
  • 24
  • 40