Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Doubt related to casting

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I am not able to understand that bObject1 is of type boo and it contains a new Foo() which is upcasted to boo and when we call b0bject1.abc()--it is printing the line depending upon what object the reference variable bobject1
has in it...,compiler doesn't take into account the casting....but if i send
a new Integer(5) to a method expecting an Object as argument...,I have to downcast and get the Integer object...to be able to call Integer specific methods and if I don't downcast I can only access Object specific methods,so, my question is in this example
when Iam upcasting it (please refer line of confusion above) and then call bObject1.abc () why not it is printing "in boo" (that is boo specific method)


Thanks

[edit]Add code tags. CR[/edit]
[ August 02, 2008: Message edited by: Campbell Ritchie ]
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friend
i understood your doubt ;
Since the methods are overridden the compiler chooses the method specfic to the object being created and not the reference type
when we upcast the reference it is still referring the Foo object and not a boo object. i hope you have understood else please refer to kathy sierra's book for scjp preparation
 
Dash Abhisek
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply...,it helped
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic