Review question 5 A keyboard is a type of input device. In Java we could write: class InputDevice { Char getLastCharacterEntered() { // this method returns the character last entered by // the device } } class Keyboard extends InputDevice { } A display screen, however, is a type of output device. So in this case we could write: class OutputDevice { void displayCharacter(char c) { // method to display character `c' on the device } } class DisplayScreen extends OutputDevice { } So far, so good. Now consider the touch-screen display. These are commonly used in information kiosks and museum displays. The touch screen displays information, put it provides information the computer when the users touches the screen. So is it an input device or an output device, or both? Ideally we would like to say class TouchScreen extends InputDevice, OutputDevice { } But we can't do this, because this is multiple inheritance, which is not allowed. To what extent does the Java `interface' mechanism allow us to represent the notion of a touch screen as an input device and an output device? Try to write some Java code that defines a TouchScreen class and its base classes. Discussion of Review Question 5 Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |