當前位置:編程學習大全網 - 電腦編程 - java 定義壹個矩形類,有長、寬2個屬性,有成員函數計算矩形的面積。

java 定義壹個矩形類,有長、寬2個屬性,有成員函數計算矩形的面積。

public class Test {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Rectangle R=new Rectangle(10,10);

System.out.println("面積為:"+R.Area());

}

}

class Rectangle{

public double width;

public double height;

Rectangle()

{

width=0;

height=0;

}

Rectangle(double w,double h)

{

width=w;

height=h;

}

public double Area()

{

return width*height;

}

}

  • 上一篇:臺鈴赤兔超能版和超智版區別
  • 下一篇:寶馬3系更換增壓壓力調節電機要編程嗎
  • copyright 2024編程學習大全網