Wednesday 25 November 2015

Java Tutorial : Java default Constructor


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

Employee.java
public class Employee
{

    String name;
    int age;

    /*
     * The compiler automatically provides a no-argument default constructor if
     * the class does not have any other constructor.
     * 
     * This default constructor will call the no-argument constructor of the
     * superclass. In this situation, the compiler will complain if the
     * superclass doesn't have a no-argument constructor so you must verify that
     * it does. If your class has no explicit superclass, then it has an
     * implicit superclass of Object, which does have a no-argument constructor.
     */

}
EmployeeDemoTest.java
public class EmployeeDemoTest
{

    public static void main(String[] args)
    {
        /*
         * Invokes the no-argument constructor to create a new Employee object
         * called employee.
         */
        Employee employee = new Employee();
        System.out.println("Name : " + employee.name);
        System.out.println("Age  : " + employee.age);

    }

}
Output
Name : null
Age  : 0
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ConstructorDemoDefaultconstructorApp.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ConstructorDemoDefaultconstructorApp/?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