Home : Software Terms : Method Definition

Method

A method is a subroutine attached to a specific class defined in the source code of a program. It is similar to a function, but can only be called by an object created from a class.

In the Java example below, the method getArea is defined within the class rectangle. In order for the getArea method to be used by a program, an object must first be created from the rectangle class.

class Rectangle
{
   int getArea(int width, int height)
   {
      int area = width * height;
      return area;
   }
}

Methods are an important part of object-oriented programming since they isolate functions to individual objects. The methods within a class can only be called by objects created from the class. Additionally, methods can only reference data known to the corresponding object. This helps isolate objects from each other and prevents methods within one object from affecting other objects.

While methods are designed to isolate data, they can still be used to return values to other classes if necessary. If a value needs to be shared with another class, the return statement (as seen in the example above) can be used.

Updated: April 19, 2011

Cite this definition:

http://techterms.com/definition/method

TechTerms - The Tech Terms Computer Dictionary

This page contains a technical definiton of Method. It explains in computing terminology what Method means and is one of many software terms in the TechTerms dictionary.

All definitions on the TechTerms website are written to be technically accurate but also easy to understand. If you find this Method definition to be helpful, you can reference it using the citation links above. If you think a term should be updated or added to the TechTerms dictionary, please email TechTerms!