Content deleted Content added
m Task 18 (cosmetic): eval 14 templates: del empty params (1×); del |ref=harv (9×); |
m Task 18 (cosmetic): eval 14 templates: hyphenate params (3×); |
||
Line 7:
In [[class-based programming]], methods are defined in 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|
==Overriding and overloading==
Line 13:
Method overloading, on the other hand, refers to differentiating the code used to handle a message based on the parameters of the method. If one views the receiving object as the first parameter in any method then overriding is just a special case of overloading where the selection is based only on the first argument.<ref>[http://www.codeproject.com/Articles/16407/METHOD-Overload-Vs-Overriding http://www.codeproject.com/Articles/16407/METHOD-Overload-Vs-Overriding]</ref> The following simple [[Java language|Java]] example illustrates the difference:<ref>{{cite web
|
| author = John Suzuki
| date = 2000-02-18
Line 68:
==Abstract methods==
An ''abstract method'' is one with only a [[method signature|signature]] and no [[method body|implementation body]]. It is often used to specify that a subclass must provide an implementation of the method. Abstract methods are used to specify [[Interface (computing)|interfaces]] in some programming languages.<ref>{{cite web|title=Abstract Methods and Classes|url=http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html|website=oracle.com|publisher=Oracle Java Documentation|
===Example===
|