aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes implementing interface question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "implementing interface question" Watch "implementing interface question" New topic
Author

implementing interface question

mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
Class A implements say interface I
class B is a subclass of A.
hence B (implicitly) implements interface I. right ???
class C is a subclass of B.
hence C (implicitly) implements interface I. right ???
i hope these two are right. please let me know....
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Yes you are
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
Originally posted by Shivaji Marathe:
Yes you are

if that is so.
then consider this case:
Interface MenuContainer
Class Component
Component class implements MenuContainer
class Frame is a subclass of Window which is a subclass of Component. Frame implements MenuContainer. all fine till now.
BUT what about other components, why don't they not implement MenuContainer. The api only shows that class Frame implements MenuContainer interface. why not other components ie subclasses of Components ?
(we are not including MenuComponents in this discussion, only Components)
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
I don't get you...
Component implements MenuContainer, so implicitely all subclasses of Component inherit its default implementation of MenuContainer providing an implementation for getFont() and remove(MenuComponent) to remove a PopupMenu from the Component.
Frame overrides remove(MenuComponent) in case you want to remove the MenuBar, if it is not the case the invocation is delegated to the superclass (Component) since it can only be a request for removing a PopupMenu.
Other subclasses of Components have no more work to do since only Frames may contain a MenuBar object and Component already provides a default behavior for PopupMenu...
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Originally posted by mark stone:

BUT what about other components, why don't they not implement MenuContainer. The api only shows that class Frame implements MenuContainer interface. why not other components ie subclasses of Components ?

Which subclasses of Component are you talking about exactly, Mark?
Last time I looked at http://java.sun.com/j2se/1.3/docs/api/index.html
(just a couple of minutes before I posted this) all the known subclasses of Component implement the MenuContainer interface (see the list under the heading "All Implemented Interfaces", right under the class hierarchy diagram at the top of each component's doc page). And there's no way to "unimplement" an interface that your parent class implements.


Junilu - [How to Ask Questions] [How to Answer Questions]
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
please don't blame me for this.
here are the two api 's reproduced. one is as you poined out from 1.3 and below is from 1.2 that i use.
----------------------------------------------
Class Button FROM 1.3 API
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Button
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
-----------------------------------------------
Class Button FROM 1.2 API
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Button
----------------------------------------------
and the interface definition is same in both api
java.awt
Interface MenuContainer
All Known Implementing Classes:
Component, Menu, MenuBar, Frame
----------------------------------------------
and this is where my question arose. See above the interface MenuContainer does not show any other component as implemented except Frame.

Originally posted by Junilu Lacar:

Which subclasses of Component are you talking about exactly, Mark?
Last time I looked at http://java.sun.com/j2se/1.3/docs/api/index.html
(just a couple of minutes before I posted this) all the known subclasses of Component implement the MenuContainer interface (see the list under the heading "All Implemented Interfaces", right under the class hierarchy diagram at the top of each component's doc page). And there's no way to "unimplement" an interface that your parent class implements.

[ February 01, 2002: Message edited by: mark stone ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
It shows that Component implements MenuContainer and thus implicitely all subclasses of Component implement it too...
So ?
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
val:
the api for 1.2 did not show (as does 1.3) that, for example Button implements MenuContainer interface.
and thanks for confirming that even if it is not shown in the api docs it is implemented implicitly. i just wanted to make sure that it is fine. i guess the 1.2 api docs just omitted it but in 1.3 it is shown exlicitly. again i want to make sure that the implicit implementation concept for interface was ok.
thanks all for the help. and if you guys could just confirm that 1.2 api doc missed this...
Originally posted by Valentin Crettaz:
It shows that Component implements MenuContainer and thus implicitely all subclasses of Component implement it too...
So ?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Right API 1.2 doesn't show that piece of information but in such a case if you are in doubt just go up the hierarchy (in this case from Button to Component) and you can see that Component implements MenuContainer and thus Button too since it subclasses Component.
HIH
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implementing interface question
 
Similar Threads
anonymous class
Interface question
instanceof
Where will be a is a relationship will occur?
The hard problem about "is a ,has a",and anonymous class,please clearify?