wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Polymorphic Reference & Methods" Watch "Polymorphic Reference & Methods" New topic
Author

Polymorphic Reference & Methods

Bronson King
Greenhorn

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

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...

Henry


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

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
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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:

.


kf
SCJP 5.0 (preparing for SCWCD)
Nuwan Hettiarachchi
Greenhorn

Joined: Nov 06, 2007
Posts: 9
Hi,

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.

cheers!

Nuwan
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphic Reference & Methods
 
Similar Threads
Is This program wrong according to Java?
instance variables - polymorphism(overriding)
Overriding,Overloading - Question
Casting
Most specific method.......