/* * @topic T10183 Feb 7, 2017 Inheritance Demo * @brief class MultiplyOp is a subclass (derived class) */ package week03; public class MultiplyOp extends BaseBinaryOp { //------------------------------ // constructors //------------------------------ public MultiplyOp(int left, int right) { super( left, right ); }//MultiplyOp //------------------------------ // operations //------------------------------ public void compute() { // pretend that multiplication operator // is not available // implements left * right // instead of 3 * 4 // do 4 + 4 + 4 int left = getLeft(); int result = 0; while( left-- > 0 ) { result += getRight(); } setResult( result ); }//compute }//class MultiplyOp