The Java Program: Poly.java

  1 class Base {
  2    int m1 (char c) {return c-'A';}
  3 }
  4 
  5 class Derived extends Base {
  6    int m2 (double d) {return (int)Math.round(d);}
  7 }
  8 
  9 public class Poly {
 10    // Subclass polymorphism:  m3 allows an argument of more than one type               
 11    static String m3 (Base b) {
 12       return String.format ("%03o", b.m1 ('Z'));
 13    }
 14    public static void main (String[] args) {
 15       Base  b = new Base();
 16       Derived d = new Derived();
 17       System.out.println (Poly.m3 (b));
 18       System.out.println (Poly.m3 (d));
 19    }
 20 }