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

Difference between function and method

  Author : Shailendra Chauhan
Posted On : 17 Jun 2012
Total Views : 38,445   
Updated On : 17 Jun 2012
 

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);
 }
} 


Free Interview Books
 
COMMENTS (0)
3 APR
Master Class Fast Track MVC 5 with Angular2 Development (Online)

10:30 AM -03:30 PM IST (Fast Track)

Know More
1 APR
MEAN Stack 2 Development (Classroom)

11:00 AM-12:30 PM

Know More
1 APR
ASP.NET MVC with Angular2 Development (Classroom)

4:00 PM-5:30 PM

Know More
25 MAR
Xamarin Forms : Build Cross-platform Apps (Classroom)

8:00 AM-9:30AM

21 MAR
ASP.NET MVC with Angular2 Development (Online)

09:00 PM - 11:00 PM IST( TUS, THR, SAT)

6 MAR
ASP.NET MVC with Angular2 Development (Online)

07:00 AM - 09:00 AM IST( MON, WED, FRI)

25 FEB
ASP.NET MVC with Angular2 Development (Classroom)

05:00 PM-06:30 PM

31 JAN
ASP.NET MVC with Angular2 Development (Online)

07:00 AM-09:00 AM IST(Tuesday & Thursday)

30 JAN
NODEJS & MEAN Stack 2.x Development (Online)

09:00 PM-11:00 PM IST( MON, WED, FRI)

31 DEC
ASP.NET MVC with AngularJS Development (Classroom)

09:30 AM-11:00 AM

BROWSE BY CATEGORY
 
 
LIKE US ON FACEBOOK
 

Professional Speaks

+