wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question from Dan's exam - ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question from Dan Watch "question from Dan New topic
Author

question from Dan's exam - ClassCastException

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4777
    
    8

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 ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Alan Phillips
Ranch Hand

Joined: Aug 13, 2002
Posts: 73
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 ]
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
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
Bartender

Joined: Feb 26, 2001
Posts: 4777
    
    8

Congratulations, Alan!
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Congratulation Allan. How was the exam? Any clues, advises....
Alan Phillips
Ranch Hand

Joined: Aug 13, 2002
Posts: 73
Hi Barkat! Thanks for your posts, check out my post under results!
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Congrats Alan.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question from Dan's exam - ClassCastException