• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

object variables vs. object references for SCJP

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sure this is somewhere but I cant' find it...
in Khalid's mock exam #29, one of the statements purported to be valid for a member variable is that:


The value of all object variables will be null.


Now I can see this as either a trick question because all object references are null and there are no "object variables" or a straight forward question because there are no object variables so object variables are object references.
Which is most likely correct interpretation in terms of the Exam?
Best regards,
Steve Butcher
exceptionraised@aol.com
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... it turns out that the question number is meaningless in Mughal & Rasmussen's exam, as the quetions are reshuffled each time you run the program. With a little work though I found the original question, since the single line reproduced above is FALSE unless given a bit more context:


Which of the following statements concerning the value of a member variable are true, when no explicit assignments have been made?

  • The value of an int is undetermined.
  • The value of all numeric types is zero.
  • The compiler is issued an error if the variable is used before it is initialized.
  • The value of a String variable is "" (empty string).
  • The value of all object variables will be null.


In this context, I'd take the last statement as a straightforward statement. "Object variable" seems to be an alternate way of saying "reference variable", a term used in the JLS. We often omit the word "reference" when dealing with reference types if it's otherwise clear that we're dealing with some sort of Object, because Objects are always dealt with via references in Java. You don't seem to object to the statement about a "String variable" whose "value" is a blank string, even though it's really a variable whose type is a reference to a String, whose value is a reference to a blank string. Since this sort of language quickly would become tedious, it's common usage to leave out all the "reference to" clauses most of the time, unless it's necessary to remind someone what's really going on. (As often happens in this forum, which is why a lot of us here actually will take pains to say "reference to x" instead of "x" in many cases.)
So, an "object variable" is just a reference variable, and if it's an uninitialized class variable, then it is indeed null, so the statement is true. Does that make sense?
 
sgwbutcher
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jim,
I makes sense.
I've seen so many spurious semi-colons, unreachable code, strange casts and incredibly complex contorted attempts to see if you understand a concept completely unrelated to the code that I'm starting to get paranoid.
...but then I always panic before a test (I'm taking It on Wednesday).
Steve
 
Bring out your dead! Or a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic