Please enable Javascript to correctly display the contents on Dot Net Tricks!

Difference between function and method

  Author : Shailendra Chauhan
Updated On : 17 Jun 2012
Total Views : 34,441   
 

In programming langauages we have two concepts functions and methods. functions are defined in structural language and methods are defined in object oriented langauge. The difference between both is given below :

Functions

  1. Functions have independent existence means they can be defined outside of the class. Ex:- main() function in C, C++ Language

  2. Functions are defined in structured languages like Pascal,C and object based language like javaScript

  3. Functions are called independently.

  4. Functions are self describing unit of code.

 //function main in C
void main()
{
 int a,b,c;
 a=5;
 b=6;
 c=a+b;
 printf("Sum is : %d",c);
} 

Methods

  1. Methods do not have independent existence they are always defined with in class. Ex:- main() method in C# Language that is defined with in a class

  2. Methods are defined in object oriented languages like C#, Java

  3. Methods are called using instance or object.

  4. Methods are used to manipuate instance variable of a class.

 //method sum in C#
class demo
{
int a,b,c;
public void sum()
{
 a=5;
 b=6;
 c=a+b;
 Console.WriteLine("Sum is : {0}",c);
 }
} 
YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (09:30 AM-11:00 AM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+