Answer:
The answer to this question can be given as:
Class definition:
public class Value //define class.
{
private boolean modified = false; //define the boolean variable and assign value.
private int y; // define integer variable.
public Value(int x) //define parameterized constructor
{
y = x; //holding value in variable y.
}
public Value() //define default constructor.
{
}
public int getVal() //define function getVal.
{
return y; //return value.
}
public void setVal(int x) //define function setVal.
{
y = x; //hold parameter value.
modified = true; .//hold boolean value.
}
public boolean wasModified() //define function wasModified.
{
return modified; //return value.
}
}
Explanation:
In the above class definition firstly we define a class that is "Value". In this class we constructor,methods and variables that can be described as:
- In the class we define a variable that is modified and y both variable is private but the modified variable is boolean type that is used for hold only true or false value and variable y is an integer variable.
- Then we define constructors. In this class, we define parameterized constructor and default constructor. In the default constructor, we do write anything but in the parameterized constructor we use the private variable y for the hold parameter value.
- Then we define a function getVal() and setVal(). The getVal() function is used to return private variable (y) value and setVal() function is used to set the value of y. and we also change the modified variable value that is "True".
- At the last we define a wasModified() function. In this function, we return the modified variable value.