A programmer has to write a program for an xyz program. He has recognised that both the Div and Add values are based on the same underlying Op data structure. As a result, he has written the following JUnit test code.
@Test
public void testDiv() {
Op aValue = new Div(8, 40, “String”);
assertEquals(5, aValue.getVal1());
assertEquals(“String 40 / 8 = 5”, aValue.toString());
}
Based on this code: Write an interface for Op and write the class header for Div.
—
My response is:
public interface IDiv {
String aValue();
String toString();
}
and
public class Div (int, String) {
}
is this correct?
My variant is:
and
I don’t add
toString()method toOpinterface because each object in Java implicitly extendsObjectclass which already has this method.