File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Polymorphic Reference & Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polymorphic Reference & Interfaces" Watch "Polymorphic Reference & Interfaces" New topic
Author

Polymorphic Reference & Interfaces

Nasir Munir
Greenhorn

Joined: May 31, 2002
Posts: 22
Can anybody explain
a)how polymorphic references seem to relax the type compatibility rules regarding assignment.
b)how can a class implement two intefaces each containing the same method signature.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi nasir
i know about the 2nd question. ans is - its a problem
when u implement two interfaces with same method in a class there is no compile time error or run time error but logically its not proper. which method u actually wanted to implement is not clear. also, u can't have two method implementation for two different interfaces in this case as the method name is same. so basically u r stuck but i guess u don't run into this kind of circumstances most of the time (may be 99% of the time)
i didn't understand the 1st question.
regards
maulin
Nasir Munir
Greenhorn

Joined: May 31, 2002
Posts: 22
Thanks for the help
nate saider
Greenhorn

Joined: Jun 24, 2002
Posts: 17
It sounds like we are taking the same class.... since I have similar issues.
I believe dual dispatch or multimethods come in handy in for your first question, but your question is vague.
I don't think you can have one class hierarchy implementing 2 interfaces with the same method name. BUT you can have two interfaces handling methods of the same name in separate class hierarchy.
The obvious guess from my basic knowledge of Java is that each interface has two different sets of derived subclasses inheriting these methods.
(i.e method gumbo()from interface A is being used by subclasses A, and method gumbo() of interface B is being used by subclasses B [the names A & B I used don't matter... I was just using them to point a relation between subclasses and each interface])
Maybe that is too obvious an answer... but I can't imagine why anyone would have 2 interfaces with the same method name in the same class hierarchy.
[ July 09, 2002: Message edited by: nate saider ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Try the following:

[ July 09, 2002: Message edited by: Ilja Preuss ]

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Polymorphic Reference & Interfaces
 
Similar Threads
Reg:use of interface in realtime environment
compile-time polymorphism
never satisfied with polymorphism
Polymorphism
Super and sub class