集册 Java实例教程 测试上行规则

测试上行规则

欢马劈雪     最近更新时间:2020-01-02 10:19:05

468
测试上行规则

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;

  }


  
展开阅读全文