0

Why does the JVM initialise the data fields with default values if no constructors are defined in any class? What is the need for such a procedure of calling the default constructor?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Jishnu
1

> Why does the JVM initialise the data fields with default values
AFAIK, design decision by the language implementors. Also makes sense since I wouldn't want the members of my newly created instance to have a value of 'undefined'.

> What is the need for such a procedure of calling the default constructor?
Instances in Java are created by the invocation of a series of constructors. The first line of each constructor is a call to it's superclass's constructor except in the case of 'Object' class. If Java doesn't provide a default constructor, it would become necessary for the programmer to specify a default constructor for each class so as not to break the constructor chaining mechanism and thereby the language specification.

Votes + Comments
Thank you!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.