从这个例子你可以想到JAVA多态的什么特性?

不加一句注解,请看下面内容:你会想到JAVA多态的什么特性?

1. 父类:

package com.maozj.javatnk.duotai;

import java.util.ArrayList;
import java.util.Map;

public class ParentObj {
	public void doWork(ArrayList list) {
		System.out.println("ParentObj doWork...");
	}

	public void doSport(Map map) {
		System.out.println("ParentObj doSport...");
	}
}
2. 子类:

package com.maozj.javatnk.duotai;

import java.util.HashMap;
import java.util.List;

public class ChildObj extends ParentObj {

	public void doWork(List list) {
		System.out.println("ChildObj doWork...");
	}

	public void doSport(HashMap map) {
		System.out.println("ChildObj doSport...");
	}

}

3. 测试类:
package com.maozj.javatnk.duotai;

import java.util.ArrayList;
import java.util.HashMap;

public class Client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		test1();
		System.out.println("==================================");
		test2();
	}
	
	public static void test1(){
		ParentObj po = new ParentObj();
		ArrayList list = new ArrayList();
		po.doWork(list);
		
		po = new ChildObj();
		po.doWork(list);
		
		ChildObj co = new ChildObj();
		co.doWork(list);
		
	}
	
	public static void test2(){
		ParentObj po = new ParentObj();
		HashMap map  = new HashMap();
		po.doSport(map);
		
		po = new ChildObj();
		po.doSport(map);
		
		ChildObj co = new ChildObj();
		co.doSport(map);
	}	
}

4.输出结果:
ParentObj doWork...
ParentObj doWork...
ParentObj doWork...
==================================
ParentObj doSport...
ParentObj doSport...
ChildObj doSport...

你可能感兴趣的:(java,jvm,面试,教育,中国移动)