Answer:
The following program are written in JAVA Programming Language.
//inherit the Calculator class
public class CalculatorWithMemory extends Calculator {
private double memory = 0.0; //initialize double type variable
public void save() { //define function
memory = accumulator;
}
public void recall() { //define function
accumulator = memory;
}
public void clearMemory() { //define function
memory = 0; //initialize the value
}
public double getMemory() {
return memory; // return the value in "memory" variable
}
}
Explanation:
Here, we inherit the property of the "Calculator" class.
Then, we define the private double type variable "memory" and assign value 0.0.
Then we set the function "save()" inside it we assign the value of "memory" in "accumulator" and close the function.
Then, we define the function "recall()" inside it we assign the value of "accumulator" in "memory" and close the function.
Then we set the function "clearMemory()" inside it we assign "memory" to 0.
After all, we set the double type function "getMemory()" inside we return the value of the "memory".