接口的成员变量必须是 public static final
public 和 static 我可以理解,
因为接口不能实例化,
但是为什么要是final的呢作者: 18353665932 时间: 2014-6-10 15:42
final定义的变量是只读的,一旦定义将不能被改变,定义类,他不能被继承,用于方法中,不能被重写,定义变量,变量不可变
public static final String LOAN = "loan" ;
LOAN = new String( "loan" ) //invalid compilation error
//上面是定义变量的
class PersonalLoan{
public final String getName(){
return "personal loan" ;
}
}
class CheapPersonalLoan extends PersonalLoan{
@Override
public final String getName(){
return "cheap personal loan" ; //compilation error: overridden method is final
}
}
//上方是定义方法
final class PersonalLoan{
}
class CheapPersonalLoan extends PersonalLoan{ //compilation error: cannot inherit from final class