通過父類、或者接口,將不同類型的對(duì)象向上轉(zhuǎn)型成同一種對(duì)象,同一套方法和屬性,其它的過濾不要,從而可以使用同一套邏輯、同一套代碼,實(shí)現(xiàn)批量處理他們
package com.guoyasoft.implement;
public class TestStudent {
public static void main(String[] args) {
Student wl=new Student();
wl.name="吳令";
wl.age=28;
wl.toSchool();
StudentWL wl1=new StudentWL();
wl1.name="吳令";
wl1.age=28;
wl1.toSchool();
wl1.doHomeWork("家庭作業(yè)");
wl1.learn("法語");
Student wl2=new StudentWL();
wl2.name="吳令";
wl2.age=28;
wl2.toSchool();
IStudy wl3=new StudentWL();
wl3.doHomeWork("家庭作業(yè)");
wl3.learn("法語");
}
}