What is the differe…
 
Notifications
Clear all

What is the difference between a function and a method ?

2 Posts
3 Users
0 Likes
393 Views
0
Topic starter

Function vs Method ?

2 Answers
0

In programming, the terms “function” and “method” refer to two different concepts, but they are closely related.

 

Function:

A function is a self-contained block of code that performs a specific task or operation. It is a fundamental building block of procedural programming and functional programming paradigms. Functions are typically independent of any specific object or instance. 

Method:

A method is also a block of code that performs a specific task or operation, but it is associated with an object or a class in object-oriented programming (OOP). Methods are defined within a class and operate on the data (attributes) of the class. They are like functions that belong to a particular class.
When a method is called, it is invoked on an instance of the class.

0

A function doesn’t need any object and is independent, while the method is a function, which is linked with any object. We can directly call the function with its name, while the method is called by the object’s name. Function is used to pass or return the data, while the method operates the data in a class.

Share: