0

When we have a class like this which doesn't have any constructor:

public class F {
    public void sum() {
        System.out.println("print it");
    }

How does the main method create an object of this class? Does the object already have a constructor?

    public static void main(String[] args) {
        F obj = new F();
        obj.sum();
    }
}

Does Java have a default constructor like this:

public class F() {
}
Radiodef
  • 37,180
  • 14
  • 90
  • 125
Ven Nilson
  • 969
  • 4
  • 16
  • 42

1 Answers1

6

A default, no argument constructor is created for every class for which no other constructor is defined.

This constructor has no body, and only performs the implicit call to super();, which is the same behavior seen in an explicitly created constructor.

Kon
  • 10,702
  • 6
  • 41
  • 58