What Is a Method in Programming?
A function that belongs to an object and acts on its data.
What a method is
In programming, a method is a function that belongs to an object or class and operates on that object's data. If a function is a reusable block of code that performs a task, a method is that same idea but attached to an object, defining one of the things that object can do. Methods are central to object-oriented programming, where objects bundle together their data and the methods that act on it. They are how objects do things.
Methods vs. functions
A method and a function are very similar, both are named, reusable blocks of code that can take inputs and return results. The difference is association: a plain function stands on its own, while a method belongs to an object or class and typically works with that object's data. You can think of a method as a function that lives inside an object. The terms are sometimes used loosely, but the key distinction is that a method is tied to an object.
Acting on an object's data
What makes methods special is their access to the data of the object they belong to. A method can read and change its object's properties. For example, a bank account object might have a 'deposit' method that increases the account's balance, the method works directly on that account's data. This tight connection between an object's data and its methods is the heart of object-oriented programming, keeping related state and behavior together.
How methods are called
You call a method on a specific object, usually by naming the object and then the method. Calling the deposit method on one account affects that account; calling it on another affects the other. The same method, defined once in the class, operates on whichever object you call it on, using that object's own data. This lets one method definition serve all the objects of a class, each maintaining its own separate state.
Methods and good design
Methods are how objects expose what they can do while keeping their internals private, which supports encapsulation. Outside code interacts with an object by calling its methods rather than touching its data directly, letting the object control and validate changes. Well-designed methods give an object a clear, meaningful set of actions. Thinking in terms of what methods an object should offer is a core part of designing good object-oriented software.
Why it matters
Methods are a fundamental building block of object-oriented programming, defining the actions objects can perform on their own data. Understanding them, and how they differ from plain functions, clarifies how objects combine data with behavior and how programs are structured around objects that do things. For anyone learning object-oriented programming, methods are an essential concept, right alongside objects and classes.
Related on Skillo
See also: What is a function in programming?, What is an object in programming?.
Sources
Published date reflects the original event date (2024-04-09). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Written by
Skillo Staff
0 Comments
Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.