Sunday, May 13, 2012

Difference Between Function and Method

Each language has its own lexicon of terms with special meaning. In C Programming Language, the word Function means a program routine. In Java, the term Function does not have any special meaning. Whereas Method means one of the routines that forms the implementation of a class.

First let we know what is Function?
A function is a piece of reuseable code that is called by name. In C or C++ we used to say function to a reusable code. It can be passed data to operate on (arguments / parameters) and can optionally return a result. Function is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code.

So What is Method??
A method  is a piece of code that is called by name that is associated with an object. A method is almost identical to a function but it's purpose is generally to operate on the data contained within the component (class). Method is a function that is a member of a class.

If you know little bit about Function and Method, you may noticed that "Functions stand alone and methods are members of a class."

Now You can Say: Method != Function and Function != Method [ :P] 

We can find another difference and that is: In C programmer used to say Function. In the same way java programmer used to say Method.

4 comments em “Difference Between Function and Method”

Post a Comment

Give your valuable Comment...


Programming, Data Structures & Algorithms Copyright © 2011 -- Template created by JAK -- Powered by Blogger