Ask Question
3 January, 22:45

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.

+3
Answers (1)
  1. 4 January, 00:09
    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?
Find 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 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