Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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.
- class testHello{
- public static void method(){
- System.out.println("This method has no parameters.");
- }
- public static void method(int n){
- System.out.println("This method has an integer as a parameter.");
- }
- public static void method(int m, String n){
- System.out.println("This method has an integer & a string as parameters.");
- }
- public static void method(String n, int m){
- System.out.println("This method has a string and an integer as parameters.");
- }
- public static void main(String args[]){
- method();
- method(-500);
- method(2012,"shailrshah");
- method("pastebin", 2013);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement