Thursday, 26 November 2015

Java Tutorial : Java overloaded Constructors


Click here to watch in Youtube :
https://www.youtube.com/watch?v=5Kqdc087J4o&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java overloaded Constructors 
Java Tutorial : Java overloaded Constructors 
Employee.java
public class Employee
{

    private String name;
    private int age;

    public Employee()
    {
        System.out.println("Inside Employee() constructor");
    }

    public Employee(String name)
    {
        System.out.println("Inside  Employee(String name) constructor");
        this.name = name;
    }

    public Employee(String name, int age)
    {
        System.out.println("Inside  Employee(String name,int age) constructor");
        this.name = name;
        this.age = age;
    }

    public Employee(int age)
    {
        System.out.println("Inside  Employee(int age) constructor");
        this.age = age;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getAge()
    {
        return age;
    }

    public void setAge(int age)
    {
        this.age = age;
    }

}
EmployeeDemoTest.java
public class EmployeeDemoTest
{

    public static void main(String[] args)
    {

        Employee employeeObject1 = new Employee();
        System.out.println("Name : " + employeeObject1.getName());
        System.out.println("Age  : " + employeeObject1.getAge());

        System.out.println("------------------------------------");

        Employee employeeObject2 = new Employee("Dave");
        System.out.println("Name : " + employeeObject2.getName());
        System.out.println("Age  : " + employeeObject2.getAge());

        System.out.println("------------------------------------");

        Employee employeeObject3 = new Employee("John", 45);
        System.out.println("Name : " + employeeObject3.getName());
        System.out.println("Age  : " + employeeObject3.getAge());
        
        System.out.println("------------------------------------");

        Employee employeeObject4 = new Employee(54);
        System.out.println("Name : " + employeeObject4.getName());
        System.out.println("Age  : " + employeeObject4.getAge());

    }

}
Output
Inside Employee() constructor
Name : null
Age  : 0
------------------------------------
Inside  Employee(String name) constructor
Name : Dave
Age  : 0
------------------------------------
Inside  Employee(String name,int age) constructor
Name : John
Age  : 45
------------------------------------
Inside  Employee(int age) constructor
Name : null
Age  : 54
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ConstructorDemoOverloadedApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ConstructorDemoOverloadedApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ConstructorDemoOverloadedApp/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment