Answer:
The Java code is given below
Explanation:
<u>Window.java:
</u>
public class Window {
private int width, height;
public Window(int width, int height) {
this.width = width;
this.height = height;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
@Override
public String toString() {
return "Window [width=" + width + ", height=" + height + "]";
}
}
<u>TitledWindow.java:
</u>
public class TitledWindow extends Window {
private int barHeight;
public TitledWindow(int width, int height, int barHeight) {
super(width, height);
this.barHeight = barHeight;
}
public int getClientAreaHeight() {
return barHeight + super.getHeight();
}
@Override
public String toString() {
return "TitledWindow [width=" + super.getWidth() + ", height=" + super.getHeight() + ", barHeight=" + barHeight + "]";
}
}
<u>TestWindows.java:
</u>
public class TestWindows {
public static void main(String args[]) {
Window w = new Window(450, 200);
System.out.println("Window: " + w);
TitledWindow titledWindow = new TitledWindow(450, 200, 30);
System.out.println("titaledWindow: " + titledWindow);
System.out.println("titledWindow.height: " + titledWindow.getClientAreaHeight());
}
}