Add a string instance variable messageUponExiting a string
Add a string instance variable , messageUponExiting (a string ), to the Window class . This variable will be used to display a message when the user closes the window (for example \"are you sure you want to quit\"). Furthermore, this variable should be accessible to all subclasses of the Window class (as each sort of window may require a different message upon exiting). Please provide the declaration of the instance variable only-- nothing else.
Solution
class Window //Base Class
{
public String messageUponExiting; //instance variable accessible to all subclasses
Window(String message)
{
messageUponExiting=message;
}
void display()
{
System.out.println(\"Exit message:\"+messageUponExiting);
}
}
class subWindow extends Window
{
subWindow(String msg)
{
super(msg); //calls base class parameterised constructor
}
}
class Test
{
public static void main(String args[])
{
subWindow ob=new subWindow(\"are you sure you want to quit\");
ob.display();
}
}
