我在Eclipse中编写了这个Java接口程序,但是在MyTriangle tmp = new MyTriangle();下面有一条红线,并且当我运行程序时,会出现以下错误:
类型Question1的封闭实例不可访问。 必须使用类型Question1的封闭实例限定分配(例如,在Question1的实例x.new A()中,x是Question1的实例)。
public static void main(String[] args)
{
MyTriangle tmp = new MyTriangle();
tmp.getSides();
System.out.println();
System.out.println("The area of the triangle is " + tmp.computeArea());
}
interface Triangle
{
public void triangle();
public void iniTriangle(int side1, int side2, int side3);
public void setSides(int side1, int side2, int side3);
public void getSides();
public String typeOfTriangle();
public double computeArea();
}
class MyTriangle implements Triangle
{
private int side1,side2,side3;
public void triangle()
{
this.side1 = 3;
this.side2 = 4;
this.side3 = 5;
}
}