Mitja Kancler wrote:I think, that the word initialized sould be replaced with declared. Instance variables has default initialization, so i belive that is not an issue.
You are correct! Instance (and class/static) variables are assigned a default value if not explicitly initialized. The following code snippet compiles successfully, although line1 refers to the instance variable name before it is initialized on line2. So that confirms your statement
But even replacing "initialized" with "declared" is not 100% accurate. You can indeed not refer to an instance variable before it is declared if you are using the simple name of the variable (as illustrated in this code snippet)But if you qualify the instance variable with this., you can refer to an instance variable even before it is declared. The Person3 class compiles without any errors and prints null
Mitja Kancler wrote:I belive that the variable name is not instance variable, so it must be local. Where does it get created? Is it created on the stack even thou there was no method call?
You are correct! The variable name is indeed not an instance variable, nor a class (static) variable. It is a local variable and its scope is the instance initializer block. That means that the variable will exist only during the execution of this instance initializer block. So you can have multiple instance initializer blocks defining a variable name and the code will still compileOnce the instance initializer block is executed, the variable name will be created on the stack (and the object it refers to, will be placed on the heap).
Finally, keep in mind that a local variable must be initialized before it is used/accessed. So the code snippet from your previous post will not compileIn this topic you'll find an overview about the initialization for class (static), instance and local variables (even when they are marked as final).
Mitja Kancler wrote:I also have a question about question 14 on page 46:
i was compiling the code and the package name didn't matter, as long as i was compiling with: javac named\A\Bird.java (on windows). Am i missing something?
Could you create another topic for this question? That will make it much easier to keep an overview (for other ranchers as well) and less confusing because answers to different questions are not interfering with each other. Thanks for your friendly cooperation!