Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Method (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Function that is tied to a particular instance or class}} A '''method''' in [[object-oriented programming]] (OOP) is a [[Procedure (computer science)|procedure]] associated with an [[Object (computer science)|object]], and generally also a [[Message passing|message]]. An object consists of ''state data'' and ''behavior''; these compose an [[Interface (object-oriented programming)|''interface'']], which specifies how the object may be used. A method is a behavior of an object parametrized by a user. Data is represented as [[Property (programming)|properties]] of the object, and behaviors are represented as methods. For example, a <code>Window</code> object could have methods such as <code>open</code> and <code>close</code>, while its state (whether it is open or closed at any given point in time) would be a property. In [[class-based programming]], methods are defined within a [[class (computer science)|class]], and objects are [[Instance (computer science)|instances]] of a given class. One of the most important capabilities that a method provides is ''[[method overriding]]'' - the same name (e.g., <code>area</code>) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the implementation of those behaviors to the receiving object. A method in [[Java (programming language)|Java]] programming sets the behavior of a class object. For example, an object can send an <code>area</code> message to another object and the appropriate formula is invoked whether the receiving object is a <code>rectangle</code>, <code>circle</code>, <code>triangle</code>, etc. Methods also provide the interface that other classes use to access and modify the properties of an object; this is known as [[Encapsulation (computer programming)|''encapsulation'']]. Encapsulation and overriding are the two primary distinguishing features between methods and procedure calls.<ref>{{cite web|title=What is an Object?|url=http://docs.oracle.com/javase/tutorial/java/concepts/object.html|work=oracle.com|publisher=Oracle Corporation|access-date=13 December 2013}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)