public?abstract?class?Xiangz???
//定義個(gè)shape的抽象類
{
public?abstract?void?ZhouChang();
//定義一個(gè)抽象的方法zhouchang
public?abstract?void?MianJi();
//?定義一個(gè)抽象的方法mianji
}
//定義一個(gè)矩形類并繼承shape類
public?class?Rectangle?extends?Shape??
{
private?int?x=8;???
//定義一個(gè)私有的變量x保存矩形的長(zhǎng)
private?int?y=4;????
//定義一個(gè)私有的變量y保存矩形的寬
?int?z=(x+y)*2;
?int?m=x*y;
????//復(fù)寫父類的zhouchang方法并打印輸出
public?void?ZhouChang()
{
System.out.println("矩形的周長(zhǎng)為:"+z);
}
??????//復(fù)寫父類的mianji方法并打印輸出
public?void?MianJi()
{
System.out.println("矩形的面積為:"+m);
}
}
public?class?Circular?extends?Shape
{
private?double?pai=3.14;??
//定義一個(gè)私有變量pai
private?int?r=3;?????
//定義一個(gè)私有變量r保存圓的半徑
double?z=pai*r*2;
?double?m=pai*r*r;
//復(fù)寫父類的zhouchang方法并打印輸出
public?void?ZhouChang()
{
System.out.println("圓的周長(zhǎng)為:"+m);
}
//復(fù)寫父類的mianji方法并打印輸出
pubic?void?MianJi()
{
System.out.println("圓的面積為:"+z);
}
}
public?class?CeShi
{
public?static?void?main(String[]?args)?
{
Rectangle?x=new?Rectangle();
x.ZhouChang();
x.MianJi();
Circular?w=new?Circular();
w.ZhouChang();
w.MianJi();
}
}
java 的抽象對(duì)象問(wèn)題,代碼有錯(cuò)誤嗎,為什么dos提示很多看不懂的錯(cuò)誤啊
qq_一切隨風(fēng)_3
2016-05-08 00:24:16