接口是更彻底的抽象
接口中的成员有固定的修饰符
1、全局常量 public static final
2、抽象方法public abstract
接口中成员的修饰符可以省略不写,编译器会自动加上。
但是不写修饰符会造成程序阅读性较差。
因此还是应该加上修饰符
interface Demo
{
/* public static final */ int NUM = 7;
/* public abstract */ void show1();
/* public abstract */ void show2();
}
class DemoImpl implements Demo
{
public vodi show1()
{}
public vodi show1()
{}
}
class Run
{
public static void main(String[] args)
{
DemoImpl d = new DemoImpl;
System.out.println(d.NUM); //3个输出都为7
System.out.println(DemoImpl.NUM);
System.out.println(Demo.NUm);
}
}