public class Main{
public static void main(String args[]){
Triangle t = new Triangle(3, 4);
System.out.println("Area of Triangle: "+t.Area());
}
}
class Triangle{
private final double height;
private final double bottom;
Triangle(double H, double B){
height = H;
bottom = B;
}
public double Area(){
return height*bottom/2;
}
}
Java程序:定义2个以上的类,并且相互调用。一个类是三角形类,一个类是主类,在主类中调用三角形类创建三角形对象,计算三角形的面积,并输出
最新推荐文章于 2025-08-11 09:20:14 发布