接口中的域

来源:互联网 发布:硕思logo软件注册码 编辑:程序博客网 时间:2024/05/22 03:32

接口中的域自动为static,final的


interface Shop {

int id = 1;
void showId();
}


class ShoeShop implements Shop {
public void changeId() {
//The final filed Shop.id cannot be assigned
//this.id  = 2;
}

public void showId() {
System.out.println("ID: " + this.id);
}
}


class ClothShop implements Shop {
public void showId() {
System.out.println("ID: " + this.id);
}
}


public class MyEx17 {
public static void main(String[] args) {
ShoeShop ss = new ShoeShop();
ClothShop cs = new ClothShop();
ss.showId();
cs.showId();
}
}