package cn.exp; //编译看左边,执行看右边 //所以:TestInterface demo=new TestInterface();要是写成 //InterfaceDemo demo=new TestInterface();在demo.out()会报错 //因为在编译的时候要检查InterfaceDemo接口中是否有out()方法 interface InterfaceDemo{ public void show(); } public class TestInterface implements InterfaceDemo{ @Override public void show() {} public void out(){ System.out.println("out"); } public static void main(String[] args) { TestInterface demo=new TestInterface(); demo.out(); } }