Advertisement
Shailrshah

Method Overloading

Dec 17th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. //Method Overloading is a feature found in many programming languages that allows creation of several methods of the same name but different types of parameters. Two methods can have the same name and parameter types, if the order of parameters is different. The return type doesn't matter. It's a compile-time polymorphism, used for extending a method's behavior.
  2. class testHello{
  3.         public static void method(){
  4.                 System.out.println("This method has no parameters.");
  5.         }
  6.         public static void method(int n){
  7.                 System.out.println("This method has an integer as a parameter.");
  8.         }
  9.         public static void method(int m, String n){
  10.                 System.out.println("This method has an integer & a string as parameters.");
  11.         }
  12.         public static void method(String n, int m){
  13.                 System.out.println("This method has a string and an integer as parameters.");
  14.         }
  15.         public static void main(String args[]){
  16.                 method();
  17.                 method(-500);
  18.                 method(2012,"shailrshah");
  19.                 method("pastebin", 2013);
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement