Constructor Overloading in Java
Constructor Overloading means when a class contain more than one method whose names are same as class name and parameter list is different . Here is an example .
public class ConstOverloadDemo
{
ConstOverloadDemo(String str)
{
System.out.print(str);
}
ConstOverloadDemo(String name ,int i)
{
System.out.print("Name : "+name+" , "+"Age : "+i);
}
public static void main(String[] args)
{
ConstOverloadDemo myObject = new ConstOverloadDemo("Constructor Overloading : ");
ConstOverloadDemo myObject1 = new ConstOverloadDemo("Joes",25);
}
}
Output : Constructor Overloading : Name : Joes , Age : 25
Find us :
Facebook : @apnaandroid
Google+ : Apna Java
YouTube : Android & Java Tutorial
public class ConstOverloadDemo
{
ConstOverloadDemo(String str)
{
System.out.print(str);
}
ConstOverloadDemo(String name ,int i)
{
System.out.print("Name : "+name+" , "+"Age : "+i);
}
public static void main(String[] args)
{
ConstOverloadDemo myObject = new ConstOverloadDemo("Constructor Overloading : ");
ConstOverloadDemo myObject1 = new ConstOverloadDemo("Joes",25);
}
}
Output : Constructor Overloading : Name : Joes , Age : 25
Find us :
Facebook : @apnaandroid
Google+ : Apna Java
YouTube : Android & Java Tutorial
Comments
Post a Comment