Function overloading: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
'''Method overloading''' is a feature found in various [[objectprogramming orientedlanguage]]s such as [[Ada (programming language)|Ada]]s such as, [[C Sharp (programming language)|C#]], [[C++]] and [[Java (programming language)|Java]] that allows the creation of several [[subprogram|function]]s with the same name which differ from each other in terms of the type of the input and the type of the output of the function.
 
An example of this would be a [[Square (algebra)|square]] function which takes a number and returns the square of that number. In this case, it is often necessary to create different functions for [[Integer (computer science)|integer]] and [[floating point]] numbers.
Line 8:
 
==Constructor overloading==
In mostsome languages[[object oriented]] [[programming language]]s, [[Constructor (computer science)|constructors]] can also be overloaded,. soIn languages that thererequire canconstructors beto morehave thanthe onesame constructorname foras athe declaring [[class (computer science)|class]], eachconstructor havingoverloading allows multiple ways of creating an object. The constructors must have different parameter types and numbers of [[parameter (computer science)|parameters]].
 
For example, athe example class <tt>Person<tt> thatbelow, written in [[Java (programming language)|Java]], holds data about each person's name and phone number. In the example below, written in [[Java (programming language)|Java]], theThe constructor is ''overloaded'' as there are two constructors for the class <tt>Person<tt>.
Constructor overloading allows multiple ways of creating an object using constructors with different parameter types and numbers of [[parameter (computer science)|parameters]].
 
For example, a class <tt>Person<tt> that holds data about each person's name and phone number. In the example below, written in [[Java (programming language)|Java]], the constructor is ''overloaded'' as there are two constructors for the class <tt>Person<tt>.
 
<source lang="java">
Line 68 ⟶ 66:
*[[Method signature]]
 
[[Category:Object-oriented programmingProgramming]]
[[es:Sobrecarga]]
[[ja:多重定義]]