Overloading based on the order of the arguments : Overloading « Class « Java






Overloading based on the order of the arguments

Overloading based on the order of the arguments
// : c04:OverloadingOrder.java
// Overloading based on the order of the arguments.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

public class OverloadingOrder {

  static void print(String s, int i) {
    System.out.println("String: " + s + ", int: " + i);
  }

  static void print(int i, String s) {
    System.out.println("int: " + i + ", String: " + s);
  }

  public static void main(String[] args) {
    print("String first", 11);
    print(99, "Int first");
  }
} ///:~



           
       








Related examples in the same category

1.Demonstration of both constructor and ordinary method overloadingDemonstration of both constructor and ordinary method overloading
2.Overloaded constructor
3.Overloaded methodOverloaded method
4.Demonstration of overriding fieldsDemonstration of overriding fields
5.Promotion of primitives and overloadingPromotion of primitives and overloading
6.Overloading a base-class method name in a derived class does not hide the base-class versionsOverloading a base-class method name in a derived class does not hide the base-class versions
7.Demotion of primitives and overloading