Ask Question
30 May, 10:58

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.

+3
Answers (1)
  1. 30 May, 13:00
    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?
Find 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 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