• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Doubt with object references

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given:

Taken from Sun e-Practice Mock Exam for JAVA 5 SCJP



What is the result?

A. true
B. false
C. Compilation fails.
D. The output is unpredictable.
E. An exception is thrown at runtime


My answer : B because wr3 and w/wr1 are pointing to the same object while w2/wr2 is pointing to another different object.


Correct answer :
Option A is correct. The output is true because the two reference variables refer to the same object.


Can I know your answers... 4 days left to my exam :/ thanks all
[ September 12, 2007: Message edited by: Brandon Bay ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see the Object and references below

w = Ob1
w2 = Ob2
Inside the method

wr1 = Ob1
wr2 = Ob2

wr3 = wr1 = Ob1
wr1 = wr2 = Ob2
wr2 = wr3 = Ob1
Back to Main

w2 = wr3 = Ob1

Now w==w2

So the answer is true

Hope it helps
 
Brandon Bay
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I've missed something, I thought the assignments in "go" method would change the references in "main" method too. My bad.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps, this thread may help you a little more.
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic