标签:1.3 def 接口 like case 今天 多个 down switch
接口另一主要功能,马克-to-win: 可以使用接口来引入多个类的共享常量。所有的这些变量名都将作为常量看待。所有定义在接口中的常量都默认为public、static和final。原因见后面。
note: the following example class Client and Server use the constants like NO and Yes at the same time, so, they define the constants in the interface of ConstantbaseM_to_win.
例1.3:
interface ConstantbaseM_to_win {
static int NO = 0;
int YES = 1;
}
class Server implements ConstantbaseM_to_win {
int answer() {
//通过其他渠道知道,今天不下雨
return NO;
}
}
class Client implements ConstantbaseM_to_win {
static void ask(int result) {
switch (result) {
case NO:
System.out.println("不下雨");
break;
case YES:
System.out.println("下雨");
break;
}
}
}
public class Test {
public static void main(String args[]) {
Client c = new Client();
。。。。。。。。。。。。。。。。。
详情请进:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner4_web.html#InterfaceHoldConstants
标签:1.3 def 接口 like case 今天 多个 down switch
原文地址:https://www.cnblogs.com/mark-to-win/p/9693661.html