View RSS Feed

Java Object

Overloading Methods

Rate this Entry
by , 04-26-2012 at 06:41 PM (703 Views)
Overloading methods are supported by the Java programming language and methods could be distinguished by Java using various method signatures. Within class, methods might be having similar name when different lists of parameters are present.

Let us assume that a class is there which uses calligraphy for different data type drawing and which have a method to draw each type of data. New names are used for every method, like drawString, drawFloat and drawInteger & so on. Same name could be used in Java programming language for all of the drawing methods however varying argument list is passed to each method. Hence, class for data drawing may declare 4 methods that is named draw, each having different list of parameter.
Java Code:
public class DataArtist {
    ...
    public void draw(String s) {
        ...
    }
    public void draw(int i) {
        ...
    }
    public void draw(double f) {
        ...
    }
    public void draw(int i, double f) {
        ...
    }
}

Submit "Overloading Methods" to Facebook Submit "Overloading Methods" to Digg Submit "Overloading Methods" to del.icio.us Submit "Overloading Methods" to StumbleUpon Submit "Overloading Methods" to Google

Categories
Overloading

Comments