Java: Default constructor

This entry is part 28 of 54 in the series Learn Java

It is possible to create a class even if no constructors are defined.

This is because the compiler will then automatically create a default parameterless constructor.

package javaapplication21;

public class Print {

    public static void main(String[] args) {

        Print print = new Print();

        print.printOut();
    }

    public void printOut() {
        System.out.println("Hello");
    }
}

defaultconstructor

Series Navigation<< Java: Constructor chaining
Java: Null object >>