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

question from Dan's exam - ClassCastException

 
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Alan--and I know you're probably as exasperated as I am at this point--but your code supports my assertion, not yours. I'll try one more time to set you straight.

subcl1 and super1 are merely references to objects. The references subcl1 and super1 are what are involved in casting. They are not the objects themselves.
The objects are the entities that are created by new. They are NOT affected by casting at all. You do not deal with them directly but access them through the references subcl1 and super1.
I'm really sorry if I sound exasperated but I sort of am...
[ September 17, 2002: Message edited by: Junilu Lacar ]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohhhhhh, We're on the same page, we just don't think we are.
Oh yeah, I get that the cast doesn't really do anything it's just there to mess you up on the mock ? I had. (I read in a couple of books that it's good practice to put it there so other programmers know you meant to do it - well, if you didn't mean to do it then why did you do it). Same thing occurs if you leave out the cast too!

// again, the cast in the above statement is not needed// and changes absolutely NOTHING at all. // subcl1 and super1 are both references to a // superclass and they now reference // THE SAME OBJECT: Object #2.// In fact, since nothing references Object #1 // at this point, it is now eligible for garbage collection// So at this point you only have one Object: Object #2, a superclass


I couldn't agree more. I'm sorry, I've been studying too much and maybe didn't express myself too well. In my head I'm making a distinction between the variable and the type. I should have made it clear that it is the references and not the Objects that are changing types. The references compile-time type and run-time type are different, Objects stay the same.
I just passed scjp 1.4 this morning...And let's just say that this discussion may have gotten me a much needed point, so big big thanks guys!!!
[ September 17, 2002: Message edited by: Alan Phillips ]
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alan Phillips:
I just passed scjp 1.4 this morning...And let's just say that this discussion may have gotten me a much needed point, so big big thanks guys!!!


Congratulations, Alan! Best of luck on your next step
 
Junilu Lacar
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulations, Alan!
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulation Allan. How was the exam? Any clues, advises....
 
Alan Phillips
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Barkat! Thanks for your posts, check out my post under results!
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congrats Alan.
 
it's a teeny, tiny, wafer thin 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