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() {
}
1
  • 1
    See here. Commented May 12, 2015 at 14:42

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.