18
JunIn 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
Functions have independent existence means they can be defined outside of the class. Ex:- main() function in C, C++ Language
Functions are defined in structured languages like Pascal, C and object-based language like javaScript
Functions are called independently.
Functions are a 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
Methods do not have independent existence they are always defined within a class. Ex:- main() method in C# Language that is defined within a class
Methods are defined in object-oriented languages like C#, Java
Methods are called using instance or object.
Methods are used to a manipulate the 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); } }Read More Articles Related to oops
Summary
In this article, I try to explain the difference between method and function. I hope after reading this article you will be able to understand the difference between method and function. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.
Take our free skill tests to evaluate your skill!

In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.