my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Chapter 3 - SELF TEST - Page 269 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Chapter 3 - SELF TEST - Page 269" Watch "Chapter 3 - SELF TEST - Page 269" New topic
Author

Chapter 3 - SELF TEST - Page 269

fadi aboona
Ranch Hand

Joined: Apr 25, 2010
Posts: 71
The following code:


the following output:


The answer in the book doesn't mention object c3, only c1 and the wrapper Short are eligible for collection.
Asad Zubair
Ranch Hand

Joined: May 08, 2011
Posts: 44

Hi Fadi,
Please try and use the code tags to make it easier for your fellow ranchers to read your code and help you out. You can see below how nice it looks with the code tags
To answer your question, understand that c3 is not an object. It is a variable reference that could point to a CardBoard object. Here, c3 is pointing to the result of c1.go(c2) which turned out to be null. So c3 is not pointing at any object to begin with.




OCPJP6
fadi aboona
Ranch Hand

Joined: Apr 25, 2010
Posts: 71
Asad Zubair wrote:Hi Fadi,
Please try and use the code tags to make it easier for your fellow ranchers to read your code and help you out. You can see below how nice it looks with the code tags
To answer your question, understand that c3 is not an object. It is a variable reference that could point to a CardBoard object. Here, c3 is pointing to the result of c1.go(c2) which turned out to be null. So c3 is not pointing at any object to begin with.





Thanks Asad, you're truly Asad
i will envelope my code with the code tags going forward.
I missed that c3 is not an object yet, it's only a reference. There are so many details that i tend to forget!! you know i'm not young anymore and it's hard to remember :-(

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chapter 3 - SELF TEST - Page 269
 
Similar Threads
Problem in question from K&B
GC question (K&B SCJP 6)
Garbage collection
Garbage collection
Is Java language works as pass by reference mechanism in case of objects?