接口作为返回值类型

/**
 * 接口作为返回值类型
 * @author Administrator
 *
 */
interface Loves{
	public abstract void loves();
}
class LoveDemos{
	public Loves getLoves(){
		return new TS();//多态,父类引用指向子类对象
	}
}

class TS implements Loves{

	@Override
	public void loves() {
		// TODO Auto-generated method stub
		System.out.println("学习");
	}
	
}

public class InterfaceReturn {
	public static void main(String[] args){
		LoveDemos ld = new LoveDemos();
		Loves l = ld.getLoves();//new TS();Love l = new TS();多态
		l.loves();
	}
}

猜你喜欢

转载自blog.csdn.net/weimeig/article/details/80193250