23,407
社区成员
发帖
与我相关
我的任务
分享
//代码一
/*父类Rectangle代码*/
class Rectangle{
int len;
int width;
Rectangle(int l,int w){
len=l;
width=w;
}
void getPerimeter(){
System.out.println("长为"+len+"宽为"+width+"的周长是"+2*(len+width));
}
}
/*子类Square代码*/
class Square extends Rectangle{
Square(int l){
super(l,l);
}
void getPerimeter(){
System.out.println("边长为"+len+"的周长是"+4*len);
}
}
//代码二
/*父类Rectangle代码*/
class Rectangle{
int len;
int width;
Rectangle(int l,int w){
len=l;
width=w;
}
void getPerimeter(){
System.out.println("长为"+len+"宽为"+width+"的周长是"+2*(len+width));
}
}
/*子类Square代码*/
class Square extends Rectangle{
Square(int l){
len=l;
width=l;
}
void getPerimeter(){
System.out.println("边长为"+len+"的周长是"+4*len);
}
}