I have a question on page 128 of Bruce Eckel’s Thinking In Java 4th Edition, the second paragraph, the last sentence it asks:
what would happen if an overloaded constructor were defined that did not initialize
w3and there wasn’t a “default” initialization forw3in its definition?
I found this statement is confusing to understand, could experts or readers of this book help me a little? Thanks!
Window w3 = new Window(3);It is just guarding if someone does not initialize
w3properly in the overloaded constructor. Such field instantiation is automatically put at the beginning of each constructor. So even the overloaded one will receive thew3initialization.If you declare only
Window w3, thenw3will remainnullwhen the overloaded constructor is executed.Here is the code from the book: