The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


interfaces vs superclasses

Posted by richard on December 26, 2000 at 9:34 PM

> An I nterface can extend more than one interface . What is the practical use of this ????

Actually you only extend classes and you can only extend (inherit from) one superclass in Java. An interface consists of abstract methods only (an abstract method has no code) and you write the appropriate code for each method in the interface, eg you must write an actionPerformed(ActionEvent) method if you inmplement the ActionListener interface. However, if you want to implement more than one interface you can, for example you may, in an application rather than an Applet, want to extend WindowListener AND ActionListener to react to action events and window events (but one interface is not, in any sense, extending another). Remember, you have not inherited any functionality from these interfaces, they don't really DO anything for you in the sense that, say, extending Frame provides methods you can use (setTitle, setSize and so on).

Don't know if that clears anything up or not!




Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us