What kinds of constructors does Java have? When does the compiler add a default constructor, and when does it stop?
Show the explanation
A constructor has the class name and no return type; it runs when new creates an object.
- Default constructor — added by the compiler only if you write no constructor at all. It takes no arguments and just calls
super(). - No-arg constructor — one you write yourself with no parameters.
- Parameterised constructor — takes arguments to initialise the fields.
class Student {
private final String name; private int year;
Student(String name, int year) { this.name = name; this.year = year; }
Student(String name) { this(name, 1); } // chaining to the main constructor
}
// new Student(); // compile error: once you add any constructor, no default one is generatedThat last point causes a classic error: if a parent class declares only a parameterised constructor, every subclass constructor must call super(args) explicitly, because the implicit super() has nothing to call. Java has no built-in "copy constructor", but you can write one (Student(Student other)) as a clear alternative to clone().
Original UniCircle question. Last reviewed 22 Oct 2026.
