/*class Rectangle
{//實(shí)例變量
?private double width;//類成員的訪問控制,不允許對象通過點(diǎn)符號,來直接訪問該變量,
?private double height;
?//方法
?public double Area()???????? //返回值類型 方法名字(){具體的實(shí)現(xiàn)語句;}
? {return width*height;} //求矩形面積
?public?double Perimeter()
? {return 2*(width+height);}//求矩形周長
//構(gòu)造函數(shù)
? public Rectangle(double width,double height) //用于變量的賦初值,
?? {
?? this.width=width;
?? this.height=height;//this關(guān)鍵字用于構(gòu)造函數(shù)參數(shù)與實(shí)例變量名字相同時(shí)候.
?? }
}
public class RectangleDemo
{
?public static void main(String [] args)
?{
??Rectangle rectangle1=new Rectangle(4,5); //矩形長寬賦值,
??System.out.println("矩形的面積是"+rectangle1.Area());
??System.out.println("矩形的面積是"+rectangle1.Perimeter());?
?}
}*/
posted on 2006-10-20 21:02
悠揚(yáng)---靖寶華 閱讀(260)
評論(0) 編輯 收藏