• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interfaces

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiya,
Given,

Now, we see that Shape has implemented the Drawinterface and Circle extends Shape (and does not explicity say that it implements the Drawinterface).
My question is do we still consider Circle as implemnting the Drawinterface.
If yes, why is it that when we call getInterfaces() fnc, it does not return Drawinterfce.
am kinda confused here..
Rex
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
circle has access to the interface through shape
but not directly
so if you try to get its interfaces it will not be there but when trying to use the method it definatly has through its parent
 
Rex Rock
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, I understand that.
My question is, is it legal to say 'circle implements Drawinterface'???
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do you mean by LEGAL
if you were giving someone an API it would not implement it
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say "no, we don't consider that Circle has implemented Drawinterface" We consider that Circle "is a" Shape, and that Shape has implemented the Drawinterface. And besides, why do you need to re-implement it? Your Circle class already extends Shape, which has done the implementation for you.
------------------------------------------------------------------------------------------------------------------
Incidentally, if you do this:This will compile and produce the same output. But it's not necessary and doesn't make sense to re-implement an interface on an object that already 'is a' object that implements the interface.
[This message has been edited by Mike Curwen (edited July 23, 2001).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that Circle does implement Drawable, and the JLS agrees. Use of the word "implements" does not necessarily imply that the implementation is contained in that particular class; the implementation can be inherited. Obviously, different people can mean different things when they use the term - but in the context of Java the JLS definition should win out, I think.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Besides, this works, and that speaks for itself :
interface C {}
class A implements C {}
class B extends A {}
public class Test extends B {

public static void main(String[] args) {

C c = new Test();
boolean b = c instanceof C;
System.out.println(b + "!");
}
}

//Kaspar
 
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic