Skip to content

Instantly share code, notes, and snippets.

@digvijaybhakuni
Created August 5, 2014 19:20
Show Gist options
  • Save digvijaybhakuni/e0f2baafb6c752b2f45c to your computer and use it in GitHub Desktop.
Save digvijaybhakuni/e0f2baafb6c752b2f45c to your computer and use it in GitHub Desktop.
Example Of Overloading
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