Like C++, Java automatically creates default constructor if there is no default or parameterized constructor written by user, and (like C++) the default constructor automatically calls parent default constructor. But unlike C++, default constructor in Java initializes member data variable to default values (numeric values are initialized as 0, booleans are initialized as false and references are initialized as null).
For example, output of the below program is
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Java Interview Questions on Constructors
- Singleton Class in Java
- Inheritance in Java
- Constructors in Java
- Constructor Chaining In Java with Examples
- Default array values in Java
- Private Constructors and Singleton Classes in Java
- How to compare two arrays in Java?
- Copy Constructor in Java
- Output of Java Program | Set 2
- Output of Java Program | Set 1
- Assigning values to static final variables in Java
- final variables in Java
- Are static local variables allowed in Java?
- What are the operators that can be and cannot be overloaded in C++?