This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes question about polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "question about polymorphism" Watch "question about polymorphism" New topic
Author

question about polymorphism

Jess Dancel
Greenhorn

Joined: Nov 07, 2007
Posts: 11
I have two classes, a Parent, and a Child. Parent has two methods, one of which is overloaded by Child.



Okay, this is very simplified. Here's my question. If later in the code, Child.initializeGUI is called, will initializeGUI call the Parent getPanel method or the Child getPanel method? I think (and hope) it's the latter, but I wanted to verify.
[ April 23, 2008: Message edited by: Jess Dancel ]
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Why don't you just give it a try, maybe identifying which of the getPanel() methods the panel comes from, eg by setting it's color before returning it? This is the best way of learning how things work ...
Jess Dancel
Greenhorn

Joined: Nov 07, 2007
Posts: 11
That's a good idea, Guido. I'm currently knee-deep in the actual code that this version represents, but I'll try compiling a simple program when I get a chance.

I am, however, interested in the academic answer as well.
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Academically, the getPanel() method of the Child class should be the one to be invoked. The only way of accessing Parent.getPanel() on a Child object is from within the Child object using super.getPanel().

Hope that helps.
Jess Dancel
Greenhorn

Joined: Nov 07, 2007
Posts: 11
Thanks, that does help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about polymorphism
 
Similar Threads
Two separate classes (not inner classes) and ActionListener question
component size
Resizing Panels inside a Jframe ??
How to get a liquid layout?
Overriding/overloading