
What is the difference between a method and a function?
Pratik Gaonkar
January 11, 2026
Understanding the difference between a function and a method is a fundamental concept in programming and object-oriented design. A function is a standalone block of reusable code, while a method is a function that belongs to an object or class. This distinction helps developers write cleaner, more structured, and maintainable code. The topic is frequently asked in technical interviews and forms the basis of many programming fundamentals. Mastering functions and methods improves code readability, reusability, and overall software design skills.
In programming, the terms function and method are often used interchangeably, especially by beginners. While they share similarities, they are not the same. Understanding their differences is a core concept in programming fundamentals and is frequently tested in technical interviews.
This guide explains functions and methods in a clear, practical way, helping you understand where each is used, how they differ, and why the distinction matters in real-world software development.
What Is a Function?
A function is a block of reusable code designed to perform a specific task. It operates independently and does not inherently belong to any object or class.
Functions accept inputs (parameters), process logic, and may return a value. They are widely used in procedural and functional programming paradigms.
- Independent and standalone
- Called directly by name
- May or may not return a value
- Common in C, Python, JavaScript
Function Example
function add(a, b) {
return a + b;
}
What Is a Method?
A method is a function that is associated with an object or a class. It defines the behavior of that object and typically operates on the object’s data.
Methods are a fundamental concept in object-oriented programming (OOP) and are invoked using an object reference.
- Belongs to a class or object
- Called using dot notation
- Can access object properties
- Supports OOP features like inheritance
Method Example
class Calculator {
add(a, b) {
return a + b;
}
}
Function vs Method Comparison
| Aspect | Function | Method |
|---|---|---|
| Association | Standalone | Bound to object or class |
| Calling Style | Direct call | Object.method() |
| OOP Support | No | Yes |
| Data Access | External | Object properties |
Interview Perspective
This question is commonly asked to test understanding of object-oriented design. You can explore more interview-focused explanations under functions and methods interview questions or read a concise answer here: difference between a method and a function .
Related Interview Questions
Frequently Asked Questions
1. Is every method a function?
Yes, conceptually a method is a type of function, but not every function qualifies as a method.
2. Can a function exist inside a class?
When a function is defined inside a class, it is called a method.
3. Do methods always require objects?
Instance methods require objects, while static methods do not.
4. Are functions faster than methods?
Performance differences are negligible and depend on language implementation.
5. Which is better for interviews: functions or methods?
Interviewers expect you to understand both and know when each is appropriate.



