Method

Introduction

Method Example Program
An example program of method usage.

In object-oriented programming, a method is a subroutine that is exclusively associated either with a class (called class methods or static methods) or with an object (called instance methods). Like a procedure in procedural programming languages, a method usually consists of a sequence of statements to perform an action, a set of input parameters to customize those actions, and possibly an output value (called the return value) of some kind. Methods can provide a mechanism for accessing (for both reading and writing) the encapsulated data stored in an object or a class. Java Applets







Static Methods

Static Method Example
An example program of static method usage.

A method may be declared as static, meaning that it acts at the class level rather than at the instance level. Therefore, a static method cannot refer to a specific instance of the class (i.e. it cannot refer to this, self, Me, etc.), unless such references are made through a parameter referencing an instance of the class, although in such cases they must be accessed through the parameter's identifier instead of this.


See Also


Community content is available under CC-BY-SA unless otherwise noted.