What is Difference between Method and Function?
Function and Methods are two different concepts used in the programming language. The main difference between these two terms is that the function is defined in the Structured Language while Methods are defined in the Object Oriented Language
Function V/S Method
Function | Method |
Functions can be declared outside the class environment. | Methods are declared within the class |
Functions are mainly defined in structured language like C, Pascal etc | Methods are defined in the Object Oriented Programming Language like Jave, C# |
Functions in any programming language are called independently. | Methods in object oriented programming language are called using the Object of Class |
Example: void main() { int x,y,z; x=10; y=20; z=x+y; printf("Sum is : %d",z); } | Example: class example { int x,y,z; public void sum() { x=5; y=6; z=x+y; Console.WriteLine("Sum is : {0}",z); } } |