Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

http://valiveru.tripod.com/java/jvaltest.html

 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 54.
True / False. Select if True

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).]
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If an object is declared in a method but not assigned nor used, it gets compiled with no error.
Any other place for a not assigned object reference non receiving its default value?
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jose I think you should read once again what Michael said.
THANKS
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic