例4-10:
class People
{double getArea(double x,int y){
return x*y;
}
int getArea(int x,double y){
return (int)(x*y);
}
double getArea(float x,float y,float z){
return (x*x+y*y+z*z);
}
}
public class Example4_10
{
public static void main(String args[]){
People zhang =new People();
System.out.println("面积:"+zhang.getArea(10,3.88));
System.out.println("面积:"+zhang.getArea(10.0,8));
}
}
结果:
面积:38
面积:80.0
输出完成 (耗时 0 秒) - 正常终止
例4-11:
public class Tom
{
int leg;
Tom(int n){
this.cry();
leg=n;
this.cry();
}
void cry(){
System.out.println("我是Tom,我现在有"+leg+"条腿");
}
public static void main(String args[]){
Tom cat =new Tom(4);
}
}
结果:
---------- 运行 ----------
我是Tom,我现在有0条腿
我是Tom,我现在有4条腿
输出完成 (耗时 0 秒) - 正常终止