java小程序大家帮忙,记住是第四个问题,和第五个

来源:百度知道 编辑:UC知道 时间:2024/05/12 09:13:32
interface rec_Area_Peri
{ int getArea();
int getPerimeter();
}

class rectangle implements rec_Area_Peri
{ int width,length;
rectangle(int w,int l)
{width=w;
length=l;
System.out.println("width="+width+"----------"+"length="+length);
}
public int getArea()
{return width*length;}
public int getPerimeter()
{return (2*(width+length));}
}
public class Ex5_1
{ public static void main(String args[])
{ rectangle rect=new rectangle(10,20);
System.out.println("矩形面积="+rect.getArea());
System.out.println("矩形周长="+rect.getPerimeter());
}
}

//200...60
/*①在实现类rectangle中注释掉一个方法后进行编译,看发生了什么?为什么?
*
*
*
②在实现类rectangle中将各实现方法前的public修饰符去掉再进行编译,看发生了什么?为什么?

③将接口rec_Area_Peri中定义的两个方法前加上abstract修饰符再编译,看对程序有影响否?为什么?

④不用单独的实现类rectangle,直接在

public class Ex5_1 {

private int length;
private int width;
public int getArea()
{
return width*length;
}
public int getPerimeter()
{
return (2*(width+length));
}

/** Creates a new instance of Ex5_1 */
public Ex5_1(int length,int width) {
this.length=length;
this.width=width;
}
public static void main(String args[])
{
Ex5_1 rect=new Ex5_1(10,20);
System.out.println("矩形面积="+rect.getArea());
System.out.println("矩形周长="+rect.getPerimeter());
}

public interface rec_Area
{
int getArea();
}
public interface rec_Perimeter()
{
int getPerimeter();
}
class rectangle implements rec_Area,rec_Perimeter
{ int width,length;
rectangle(int w,int l)
{width=w;
length=l