• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Polymorphic Reference & Interfaces

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try the following:

[ July 09, 2002: Message edited by: Ilja Preuss ]
 
I've never won anything before. Not even a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic