wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Object Reference 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 "Object Reference" Watch "Object Reference" New topic
Author

Object Reference

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159
Good evening to all



the answer is

how? cause b class instance refer the class c instance.So the the output is 30,30 but i got 30,20.
Any one explain this program
regards
rex
-----
indenting repaired, Bu.

[ September 14, 2007: Message edited by: Burkhard Hassel ]
[ September 14, 2007: Message edited by: Burkhard Hassel ]
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy,

you are quite right, b class variable refer the class c instance.

But polymorphy works with methods only, not with fields.

Therefore the b class "20".

The difference is very important.

Yours,
Bu.


all events occur in real time
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Object Reference
 
Similar Threads
ClassCastException
mock exam query
Execution
Question about polymorphism and casting
lots of "extends" ??