java

interface

不能有一般属性,只能有共有静态常量(public static final String = name) (必须赋值)  不写的话也能过编译,但是会默认设定为public static final,子类中不能修改值

不能有一般方法,只能有共有静态方法,或者default(JDK1.8)

不能含有一般程序块和静态方法。

不能含有构造方法。

可以直接继承接口,使用implements

 类使用implements继承接口,可以继承多个,用逗号隔开。

普通类必须实现接口中的方法,抽象类和接口可以不实现

package interfaceTest;

public interface InterfaceTest {
    public static final String name = "aaa";
    public static int age = 10;
    public int aaa = 20;

    public void show();
}
package interfaceTest;

public interface InterfaceTest2 {
}
package interfaceTest;

public class InterfaceTestChild implements InterfaceTest, InterfaceTest2 {

    public void show(){
        System.out.println("name = " + name + " age = " + age + " aaa = " + aaa );
    }

    public static void main(String[] args) {
        InterfaceTestChild inter = new InterfaceTestChild();
        inter.show();
    }
}
原文地址:https://www.cnblogs.com/clamp7724/p/11604779.html