
转载请保持文章完整性!
本文链接地址:http://blog.desizen.com/4lone/208.html
主页:joel's blog
最近一直都在看java的视频<
下面的这个例子是java中接口部分的讲解,其中implements了一个tiger类
interface Animal { void eat(); void sleep(); } class Zoo { private class Tiger implements Animal { public void eat() { System.out.println("T eat"); } public void sleep() { System.out.println("T sleep"); } } Animal getAnimal() { return new Tiger(); } } class Test { public static void main(String[] args) { Zoo z=new Zoo(); Animal an=z.getAnimal(); an.eat(); an.sleep(); } }

这有实例化吗?
接口是不能直接实例化的