Ask Question
3 November, 03:09

Write a class definition of a class named 'Value' with the following: a boolean instance variable named 'modified', initialized to false an integer instance variable named 'val' a constructor accepting a single parameter whose value is assigned to the instance variable 'val' a method 'getVal' that returns the current value of the instance variable 'val' a method 'setVal' that accepts a single parameter, assigns its value to 'val', and sets the 'modified' instance variable to true, and a boolean method, 'wasModified' that returns true if setVal was ever called.

+2
Answers (1)
  1. 3 November, 05:13
    0
    The following program are:

    public class Value { / / Define a class named Value which is public type

    private boolean modified = false; / / a Boolean instance variable named 'modified',

    private int val;

    public Value (int i) { val = i; }

    public int getVal () { return val; }

    public void setVal (int i) { val = i; modified = true; }

    public boolean wasModified () { return modified; }

    }

    Explanation:

    Firstly, a class defines "Value" and then take a Boolean variable "modified" initialize the value false and then take an integer variable "val" and after that we create a constructor taking a parameter in which variable is assigned to the "val" and then we create an integer type function "getVal () " which returns the value of the "val", and then we create a void type function "setVal () " which takes parameter assign to the value to the "val" and we set the value in the "modified" is true and after all we create a Boolean type function, "wasModified () " which give an output true, if the function "setVal () " was called
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a class definition of a class named 'Value' with the following: a boolean instance variable named 'modified', initialized to false an ...” 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