Use java relay and method rewriting to calculate the maximum common approx. And the minimum common multiple. the background teacher assigned several java programming questions in the class. This is one of them. write a class in the topic content. This class has a public int f (int a, int B) method, and returns the maximum public approx. of a and B. Then write a subclass derived from this class, override the f method of the ancestor, and return the minimum public multiple of a and B. When the child class overrides the parent class method, it is required that the f method of the parent class be called first to obtain the maximum public approx. m, and then use the formula (a * B)/m to obtain the minimum public multiple. Finally, write a test program to call the methods of the parent class and subclass respectively. 3. code and explanation [java] <span style = "font-family: SimSun; font-size: 14px"> package Three;/*** @ author Kun Sun * @ Date: 2013.10.15 */public class Gcd {// maximum Common Divisor class, named from the first letter (Greatest Common Divisor) public int f (int a, int B) {if (a <B) {// ensure that a is the maximum value int temp = a; a = B; B = temp;} while (B> 0) {// calculate the maximum public approx. if (a = B) {return a ;}else {int temp = a % B; a = B; B = temp ;}} return ;}} </span> [java] <span style = "font-family: SimSun; font-size: 14px"> package Three;/*** @ author Kun Sun * @ Date: 2013.10.15 */public class Lcm extends Gcd {// minimum public Multiple class, named from the first letter (Lowest Common Multiple) public int f (int a, int B) {// method rewriting, returns the smallest public multiple Gcd gcd = new Gcd (); int m = gcd. f (a, B); int result = a * B/m; return result ;}</span> [java] <span style = "font-family: SimSun; font-size: 14px "> package Three;/*** @ author Kun Sun * @ Date: 2013.10.15 */public class MainClass {// used to test the maximum public approx. class and minimum public multiples class/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub Gcd gcd = new Gcd (); int result1 = gcd. f (12, 24); System. out. println (result1); Lcm lcm = new Lcm (); int result2 = lcm. f (12, 24); System. out. println (result2) ;}</span> 4. test Run result