Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

Essential

Two different components,...

but both contain an actionPerformed method.

They have the PRESENCE OF THIS METHOD IN COMMON ,....

but the implementations DIFFER .

They both implement ActionListener.

ActionListener is an interface . Its full name is java.awt.event.ActionListener .

It contains only the description of the actionPerformed method,....

NO IMPLEMENTATION !

An interface can not contain instructions.

Because both components implement the interface, ....

they can be registered with the Button as ActionListeners.

So they're not only Panels,....

but ActionListeners, too .

A component that is NOT an ActionListener, can NOT be added as an ActionListener, because the compiler accepts only ActionListener as the parameter's data type.

As coded in the Button class source code.

This shows that an interface can be USED AS DATA TYPE .

==========
IMPORTANT :

A class that implements an interface MUST CONTAIN ALL METHODS SPECIFIED in that interface.

=========

NOTES

=========

An interface results in a binary .class file after compilation.

=======

An interface can extend another one.

=======

An interface can be empty, containing no method descriptions whatsoever. Such an interface is used JUST AS A DATATYPE, like java.io.Serializable, for instance.

.