4 回答
已采纳

诸葛浪
TA贡献4条经验 获得超6个赞
别着急同学,首先,interface定义的是接口,所以不能再有关键字class,其次,在new一个对象时应该这样,类名 自定义对象名=new 类名();这个程序也是我刚学Java时老师让写的

qq_我亦久飘零_0
TA贡献11条经验 获得超3个赞
package com.Shape;
class interface Shape
{
double area (double d);
}
class Square implements Shape{
public double area(double d);
{return d*d; }
}
class Circle implements Shape
{
public double area(double d);
{
return d*d*3.14;
}
}
public class Shape
{
public static void main(String[] args)
{
Square square =new Square;
System.out.println(Square.area(2));
}
}
添加回答
举报
0/150
提交
取消