Since when is it obligated to include an empty constructor in Java?

java, oop

Solution

Using `Dog newDog = new Dog();` will not work in your current code, because you have not defined it.

A default constructor will only be automatically generated if no other constructors are present.

You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. 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.

Source: http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

Problem

I was practicing dome Java OO principles, when I encountered with this. I create to POJOs and when trying to make objects from it, if an empty constructor isn't defined, it wont compile. I find this weird because I used to do that and the JVM included a default one for me. Is it new in Java 7? Am I missing something? Here is the sample code I made ``` public class Dog { String name; String race; int age; /* public Dog() { If this isn't included, it doesn't compile if I try to create no-args objects. }*/ public Dog (String _name) { this.name = _name; } public Dog (String _name, String _race) { this.name = _name; this.race = _race; } public Dog (String _name, String _race, int _age) { this.name = _name; this.race = _race; this.age = _age; } ``` }

Original source