Which class is super class of every class

How does Java default constructor provided

Answer : “default constructor” refers to a constructor that is automatically generated in the absence of explicit constructors.

Please see example below:

package com.javahonk.thistest;

public class ConstructorTest {

    // constructor declared
    public ConstructorTest() {
    }

    public static void main(String args[]) {
	// Objected created empty constructor called
	ConstructorTest constructorTest = new ConstructorTest();
    }

}

class ConstructorTest2 {

    public static void main(String args[]) {
	// Objected created default constructor called automatically
	ConstructorTest2 constructorTest2 = new ConstructorTest2();
    }

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *