Ask Question
1 December, 13:51

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.

+1
Answers (1)
  1. 1 December, 16:46
    0
    The abstract class Window:

    public abstract class Window

    Two integer instance variables, width and height:

    private int width, height;

    Two accessor methods, getWidth and getHeight:

    public int getWidth ()

    public int getHeight ()

    A constructor that accepts two integers and uses them to initialize the two instance variables:

    public Window (int var1, int var2) {width = var1; height = var2; }

    An abstract void-returning method named paint that accepts no parameters

    public abstract void paint ();

    Explanation:

    Abstract keyword is used with Windows class to make this class an abstract class which means no object can be created using this class.

    Two private instance variable width and height. Private means they are not accessible outside this class.

    Then getWidth and getHeight methods are used to return width and height.

    The constructor takes two integer type variables var1 and var2. These two variable are used to initialize the variables width and height. Constructor has the same name as that of the class.

    Method paint () is an abstract method with the return type void which has no parameters.

    So here is what the class with all its methods and instance variables looks.

    public abstract class Window {

    private int width, height;

    public Window (int a, int b) {width = a; height = b; }

    public int getWidth () { return width; }

    public int getHeight () { return height; }

    public abstract void paint ();

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “All windows on the desktop have width and height (as well as numerous other attributes). However the actual contents of the window change ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers