CodePudding user response:
Then you will be a class definition for the abstract, afterward again write a calculation inside draw the value of the method is not goodCodePudding user response:
import Java. Math. BigDecimal;
Public class Test1 {
The static abstract class AbsDigitalProcessor {
Public void doProcess (int a, b int, int) c {
BigDecimal result=calculate (a, b, c);
System. The out. Println (result. ToPlainString ());
//get the result to do something
}
Protected the abstract BigDecimal calculate (int a, b int, int) c;
}
Static class AvaDigitalProcessor extends AbsDigitalProcessor {
@ Override
Protected BigDecimal calculate (int a, b int, int) c {
Return new BigDecimal ((a + b + c)/(3);
}
}
Static class CountDigitalProcessor extends AbsDigitalProcessor {
@ Override
Protected BigDecimal calculate (int a, b int, int) c {
Return new BigDecimal (a + b + c);
}
}
Static class SubDigitalProcessor extends AbsDigitalProcessor {
@ Override
Protected BigDecimal calculate (int a, b int, int) c {
Return new BigDecimal (a - b - c);
}
}
Public static void main (String [] args) {
New AvaDigitalProcessor (.) doProcess (1, 2, 3);
New CountDigitalProcessor (.) doProcess (1, 2, 3);
New SubDigitalProcessor (.) doProcess (1, 2, 3);
}
}
Like this?
CodePudding user response:
Abstraction is the abstract