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

Array Ref question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question regarding the Self Test (Ch3 Page 262 in Sierra Bates SCJP 1.5 Prep Book) question no. 7.



Now as per their solution this is fine. I wanted to clarify if x is uninitilized, will this not fail to complie? Or if x were null, is it alright to assign a reference to x which would make them point to null too?

cheers,

G.

P.S. Hi, great forum and good luck to all taking the exam soon.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gaurav,

First of all u hav a gr8 name
Ya this code will compile fine as you would have noticed that
x is a instance reference variable and all instance variable are given a default value in this case it is null. And there is no error if you make two reference variable point to null. In the given case both x and d are null.

I hope that clarify your doubt.

Gaurav
 
Gaurav P
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gaurav (i.e. not myself but the poster above me who is shadowing my first name ).

Well, i tried compiling that code with my IDE (Netbeans 5) and it will not compile till I manually refer x = null. I guess its probably some compiler settings I need to tweek.

G.

P.S. Thanks for the clarification.
[ April 11, 2006: Message edited by: Gaurav P ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic