例4-5:
class Tom{
final int MAX=100;
static final int MIN=20;
}
public class Example4_5
{
public static void main(String args[]){
System.out.println(Tom.MIN);
Tom cat=new Tom();
int x=0;
x=Tom.MIN+cat.MAX;
System.out.println(x);
}
}
结果:
---------- 运行 ----------
20
120
输出完成 (耗时 0 秒) - 正常终止
例4-6:
class Computer
{
double x,y;
static double max(double a,double b){
return a>b?a:b;
}
}
class Example4_6
{
public static void main(String args[]){
double max=Computer.max(12,45);
System.out.println(max);
}
}
结果:
---------- 运行 ----------
45.0
输出完成 (耗时 0 秒) - 正常终止