Default constructor
If you do not define any constructor in a class, Java automatically provides a default constructor with no parameters. It initializes fields to their default values (0, false, null, etc.).
Example:
class Dog { String name; int age; // No constructor defined – Java adds default constructor}
Dog myDog = new Dog(); // Calls default constructorSystem.out.println(myDog.name); // nullSystem.out.println(myDog.age); // 0Important: If you define any constructor (even a parameterized one), the default constructor is not provided.
class Cat { String name; Cat(String n) { name = n; } // No default constructor}
// Cat c = new Cat(); // Error: no default constructorCat c = new Cat("Whiskers"); // OKTo have both a default and parameterized constructor, explicitly define the default one.