/** * This code is from the book: * Winder, R and Roberts, G (1998) * Developing Java Software</em> * John Wiley & Sons. * It is copyright (c) 1997 Russel Winder * and Graham Roberts. */ class Superclass{ //cannot redeclare these methods with //same name and argument types. public static final void f(){ System.out.println("Superclass f"); } public final void g(){ System.out.println("Superclass g"); } } class Subclass extends Superclass{ /*Cannot declare any of these to try would be an error public static void f(){ System.out.println("Subclass f"); } public void g(){ System.out.println("Subclass g"); } public int f(){ System.out.println("Subclass f"); return 1; } */ //These overloaded methods are OK public void f(int x){ System.out.println("Subclass f"); } public int f(double x){ System.out.println("Subclass f"); return 1; } } class l1Inherit9{//Final1 public static void main(String[] args){ Subclass sub = new Subclass(); sub.f(); sub.g(); sub.f(1); sub.f(1.1); } } /******** sample compilation & run ******* # javac l1Inherit9.java # java l1Inherit9 Superclass f Superclass g Subclass f Subclass f # ******************************************/