Created
August 5, 2014 19:20
-
-
Save digvijaybhakuni/e0f2baafb6c752b2f45c to your computer and use it in GitHub Desktop.
Example Of Overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExOverloading{ | |
private String name = null; | |
public ExOverloading(){ | |
this.name = "default"; | |
} | |
public ExOverloading(String name){ | |
this.name = name; | |
} | |
public String displayInfo(){ | |
return "The Name is "+this.name; | |
} | |
public String displayInfo(int age){ | |
return "The Name is "+this.name+" and age is "+age+" yrs"; | |
} | |
public static void main(String... args){ | |
ExOverloading obj1 = new ExOverloading(); | |
System.out.prinln(obj1.displayInfo());//The Name is default | |
System.out.prinln(obj1.displayInfo(5));//The Name is default and age is 5 yrs | |
ExOverloading obj2 = new ExOverloading("Jon Doe"); | |
System.out.prinln(obj2.displayInfo());//The Name is Jon Doe. | |
System.out.prinln(obj2.displayInfo(12));//The Name is Jon Doe and age is 12 yrs. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment