Java examples for Object Oriented Design:Method Overloading
Using Overloaded Methods in Java
public class Main { public void print(String str) { System.out.println("print(String): " + str); }//from w ww .ja va 2 s. co m public void print(Object obj) { System.out.println("print(Object): " + obj); } public void print(Double num) { System.out.println("print(Double): " + num); } public static void main(String[] args) { Main pt = new Main(); Object[] list = new Object[]{"Hello", new Object(), 10.5}; for(Object arg : list) { pt.print(arg); } } }