21156 - VictoriaBrown/MyProgrammingLab_Ch10 GitHub Wiki
QUESTION:
All windows on the desktop have width and height (as well as numerous other attributes). However the actual contents of the window change both in structure and appearance depending upon what sort of window is displayed (e.g. a word processing window will display text, a color chooser window display a pallette of colors, a file chooser window displays a directory tree, etc). Thus, the details of the method to actual fill the contents of the window must be deferred to the subclasses of the Window class Write the definition of an abstract class , Window, containing the following: two integer instance variables , width and height, two accessor methods , getWidth and getHeight, a constructor that accepts two integers and uses them to initialize the two instance variables (the parameters should be width followed by height), and an abstract void-returning method named paint that accepts no parameters.
CODE:
public abstract class Window {
// Instance variables:
private int width;
private int height;
// Constructor:
public Window(int width, int height) {
this.width = width;
this.height = height;
}
// Return width (get method):
public int getWidth() {
return width;
}
// Return height (get method):
public int getHeight() {
return height;
}
// Abstract method paint:
public abstract void paint();
}