现在的位置: 首页 > 综合 > 正文

Java类和接口的继承

2018年02月16日 ⁄ 综合 ⁄ 共 400字 ⁄ 字号 评论关闭
public interface Animal
{
	public String aniName();
}

public abstract class Cat
{
	public String aniName()
	{
		System.out.println("Tom and Jerry.");
		return "Tom and Jerry";
	}
}

public class AsianCat extends Cat implements Animal
{
	public static void main( String args[] )
	{
		Animal ani = new AsianCat();
		ani.aniName();
	}
}

这个竟然可以,将看似无关的接口和类通过一个类继承并实现。

这个就相当于,将一个类Cat不用显示的实现接口Animal,但是在AsianCat 类中却体现出了Cat实现了Animal的接口。但是和两个“类”在实际中并不用实现关系。

这个我感觉好像可以是开发插件的模式?



抱歉!评论已关闭.