Implementing an interface ?keyword 'implements' The keyword 'implements' denotes inheritance from an interface, in the same way that 'extends' denotes inheritance from a class. A class can implement any number of interfaces. The class must provide an implementation for all the methods specified by the interface Continuing the example above, if Compoment is a class, and KeyboardListener is an interface, then we specify that MyButton is a type of Component and a type of KeyboardListener as follows: class MyButton extends Component implements KeyboardListener { void keyPressed() { // instructions describing what to do when a key is // pressed } void keyReleased() { // instructions describing what to do when a key is // released } } Note that the implementation of MyButton includes implementations of the methods ` keyPressed() ' and ` keyReleased()' as specified in the keyboardListener interface. Back to top 
RITSEC - Global Campus Copyright © 1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |