
隐式变量声明:
代码示例:
// 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] + " ");
}
}
}
}
注意:虽然对于常量很有用,但这种技术可能存在争议。
接口可扩展
接口继承:
代码示例:
// 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() 的实现,将会出现编译错误,因为所有接口方法都必须实现。
以上就是接口和扩展中的变量的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号