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.
- Default Methods In Java 8
- Default array values in Java
- Replace null values with default value in Java Map
- How does default virtual behavior differ in C++ and Java ?
- Copy Constructor in Java
- Constructor Overloading in Java
- Constructor Chaining In Java with Examples
- Constructor getAnnotatedReceiverType() method in Java with Examples
- Java Function/Constructor Overloading Puzzle
- Constructor equals() method in Java with Examples
- Constructor getAnnotatedReturnType() method in Java with Examples
- Constructor newInstance() method in Java with Examples
- Constructor getTypeParameters() method in Java with Examples
- Constructor getParameterAnnotations() method in Java with Examples
- Constructor getAnnotation() method in Java with Examples