您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes
Introduction
Content
Apply
Reflect
Extend
previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Content Index
Content Page # 12

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

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg