测试上行规则
class EmpUtil { public static void printName(Employee emp){ // Get the name of employee String name = emp.getName();/* 来自 NowJava.com*/ // Print employee name System.out.println(name); } } public class Main { public static void main(String[] args) { Employee emp = new Employee(); emp.setName("Mary Bates"); Manager mgr = new Manager(); mgr.setName("Edith Bates"); // Inheritance of setName() at work /** from * 时 代 J a v a - nowjava.com **/ // Print names EmpUtil.printName(emp); EmpUtil.printName(mgr); // Upcasting at work } } class Employee { private String name = "Unknown"; public void setName(String name) { this.name = name; }