The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Polymorphic Reference & Methods 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 "Polymorphic Reference & Methods" Watch "Polymorphic Reference & Methods" New topic

Polymorphic Reference & Methods

Bronson King

Joined: May 25, 2008
Posts: 9
I want to verify that this restaurant analogy I wrote in my notes is 100% correct...

The reference type provides the menu, but the object type cooks the meals.

~B King~
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

Originally posted by Bronson King:
The reference type provides the menu, but the object type cooks the meals.

I don't have a clue what this statement means, much less if it works as an analogy.... but I am getting hungry...


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Bronson King

Joined: May 25, 2008
Posts: 9
Basically trying to burn in that only methods the reference type knows about are available, even though the actual object's method is going to be run.

The analogy works too because a cook(object) might know some dishes(his own methods) that aren't on the menu(reference) and also might put his special touches(overrides) on the available meals(methods).

Sorry if I've confused anyone, but I think I've burned this in in the process.

Bon appetit!
[ May 25, 2008: Message edited by: Bronson King ]
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

Perhaps if you post some code it will make it easier to understand

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

Actually, I like the analogy .. and you're right ... although only methods that the reference type knows about can be called (or referenced) ... what actually gets executed at run time is the implementation defined by the object being referenced. For example:


SCJP 5.0 (preparing for SCWCD)
Nuwan Hettiarachchi

Joined: Nov 06, 2007
Posts: 9

My favourite analogy is to match the TV remote control with the TV.
TV remote control is the Reference Type,
TV is the actual object.

If TV remote has switches to operate the TV will function accordingly as the instruction (methods) implemented at run time.

You can add the Casting operations in the same analogy and get this story expanded. The advantage is once you know the story, it is easy to map it back to the real OBJECTS.


Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"Nuwan H",
Please check your private messages regarding an important administrative matter.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Polymorphic Reference & Methods
It's not a secret anymore!