Ask Question
20 December, 09:10

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.

+2
Answers (1)
  1. 20 December, 09:31
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers