Write a Java-program using Constructor overloading

Write a Java-program using Constructor overloading

Program
class Demo
{
    Demo()
    {
        System.out.println("hi");
    }
    Demo(int x)
    {
        System.out.println("welcome");
    }
    Demo(int x,int y)
    {
        System.out.println("java");
    }
}
public class Main
{
    public static void main(String args[])
    {
        Demo d=new Demo();
        Demo d=new Demo(10);
        Demo d=new Demo(10,20);
    }
}

Output:

hi
welcome
java


Using this()
class Demo
{
    Demo()
    {
        this(10);
        System.out.println("hi");
    }
    Demo(int x)
    {
        System.out.println("welcome");
    }
    Demo(int x,int y)
    {
        this();
        System.out.println("java");
    }
}
public class Main
{
    public static void main(String args[])
    {
        Demo d=new Demo(10,20);
    }
}

Output:

welcome
hi
java


Polymorphism In Java



More Questions


150 . Write a Java-program using dynamic method overloading
151 . Write a Java-program using Constructor overloading
152 . Write a Java-program using static method overridding
153 . Write a Java-program using dynamic method overridding
154 . Write a java program to illustrate inner class accessing inner class properties
155 . Write a package Program
156 . Write a package program using encapsulation
157 . Write a package program using data abstraction
158 . Write a package program using inheritance
159 . write a package program using polymorphism
160 . write a inner package program using polymorphism