Ask Question
1 January, 06:44

Write a subclass named 'ReadWrite' with the following additional behavior: Any necessary constructors. a method named 'setVal' that accepts an integer parameter and assigns it the the 'val' instance variable. a method 'isDirty' that returns true if the setVal method was used to override the value of the 'val' variable.

+4
Answers (1)
  1. 1 January, 08:08
    0
    Java Class given below

    Explanation:

    class ReadOnly

    {

    protected int val;

    public ReadOnly (int arg)

    {

    val = arg;

    }

    public int getVal ()

    {

    return val;

    }

    }

    class ReadWrite extends ReadOnly

    {

    private boolean dirty;

    public ReadWrite (int arg)

    {

    super (arg);

    dirty = false;

    }

    public void setVal (int arg)

    {

    val = arg;

    dirty = true;

    }

    public boolean isDirty ()

    {

    return dirty;

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a subclass named 'ReadWrite' with the following additional behavior: Any necessary constructors. a method named 'setVal' that accepts ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers