A.Instance variables are always initiated to defaults B.Local variables are always initiated to defaults C.Array Elements are always initiated to defaults D.Object references that are not initialized explicitly will have their value set to null always Ans: A, C, My Ans: A, C, D Will I get credit?
[This message has been edited by Ragu Sivaraman (edited September 01, 2001).]
D is not always true. Object references declared in class scope are assigned to null. When a reference is declared as part of a local stack, however -- inside a method, try block, loop, or the like -- it gets no assignment by default. In that case, as a matter of fact, it's necessary to assign null explicitly whenever the compiler may think you are trying to use that reference without initializing it. For example:
The compiler should complain here of a "possible use before initialization." This is because value gets assigned only on a conditional basis. When it is first declared, it does *not* get assigned null. The compiler doesn't initialize automatic variables, but does check for initialization when a reference is used on the RHS of an expression. It's simply more efficient to make the programmer do this work. ------------------ Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Make visible what, without you, might perhaps never have been seen. - Robert Bresson
Thanks to replay Bindesh I have red again to Michael but I didn�t get your point. I will try to explain myself clearer: I think D is not true because when an Object reference declared in a method is not initialized it doesn't get the default value. But if this reference is not used the program will compile. This what my first statement meant. The second is only to ask another place where D could be false