I'm just trying to get my head around the following...
Suppose class B extends class A. Suppose also that class A implements interface I.
So I can be used as a reference type for an object of class A.
From my research it seems that this property does not extend to B. If we want to use an I reference type for an object of class B, then B must implement I also. I other words a subclass does not inherit an superclass's implemented interface
I say this because there are examples in the Sun java class library where B extends A, and both A and B implement I.
OK I have no problem dealing with this, I was just wondering why it was so.
If A implements I, then A is a I. And if B extends A, then B is a A and since A is a I, B is a I too.
Confusing but concise
your meaning is clear enough. But I am missing something, here is an example.
there is an abstract class, in package java.awt.geom I believe, called Line2D. Line2D has two subclasses Line2D.Double, and Line2D.Float. All three class are documented as implementing the interface Shape.
So, if what you say is true, what's the point of the two subclasses implementing Shape?
David Newton wrote:They may implement it in different ways.
hmmm ok I'm gonna have to think on this. Your answer makes sense to me in a way, but I'm still unclear on the why.
It's not exactly clear to me what role is played by the fact that the subclasses are nested and static. I'm not sure that is relevant to my original question.
anyways it's the sort of relationship that exists with a lot of the basic shape classes in package java.awt.geom. There is an abstract superclass for the shape, then 2 nested static concrete classes that are defined by float and double parameters respectively. Then the draw method of the Graphics2D class uses the Shape type. And Shape is the interface implemented by both.
hmm...I suppose this sort of relationship allows us to add another layer of abstraction, and perhaps allows us to refine our shapes by adding precision, without having to change method calls, just the object instantion. This in addition to the other layer of abstraction which allows us to deal with different shapes in the same way.
Anyways, just thinking out loud here. I'll have to give it time to sink in.