
隐式变量声明:
- 接口中声明的变量自动是公共的、静态的和最终的。
- 对于在大型程序中创建共享常量很有用。
代码示例:
// interface que contém constantes
interface iconst {
int min = 0;
int max = 10;
string errormsg = "boundary error";
}
class iconstd implements iconst {
public static void main(string[] args) {
int nums[] = new int[max];
for (int i = min; i < 11; i++) {
if (i >= max)
system.out.println(errormsg);
else {
nums[i] = i;
system.out.print(nums[i] + " ");
}
}
}
}
注意:虽然对于常量很有用,但这种技术可能存在争议。
接口可扩展
云点滴客户解决方案是针对中小企业量身制定的具有简单易用、功能强大、永久免费使用、终身升级维护的智能化客户解决方案。依托功能强大、安全稳定的阿里云平 台,性价比高、扩展性好、安全性高、稳定性好。高内聚低耦合的模块化设计,使得每个模块最大限度的满足需求,相关模块的组合能满足用户的一系列要求。简单 易用的云备份使得用户随时随地简单、安全、可靠的备份客户信息。功能强大的报表统计使得用户大数据分析变的简单,
接口继承:
- 接口可以通过extends关键字继承其他接口。
- 实现派生接口的类必须实现整个接口链的所有方法。
代码示例:
// Interface A
interface A {
void meth1();
void meth2();
}
// Interface B estende A
interface B extends A {
void meth3();
}
// Classe que implementa A e B
class MyClass implements B {
public void meth1() {
System.out.println("Implement meth1().");
}
public void meth2() {
System.out.println("Implement meth2().");
}
public void meth3() {
System.out.println("Implement meth3().");
}
}
class IFExtend {
public static void main(String[] args) {
MyClass ob = new MyClass();
ob.meth1();
ob.meth2();
ob.meth3();
}
}
重要提示:如果删除 meth1() 的实现,将会出现编译错误,因为所有接口方法都必须实现。









