gpt4 book ai didi

java - 类型的封闭实例不可访问

转载 作者:搜寻专家 更新时间:2023-10-31 08:06:03 26 4
gpt4 key购买 nike

<分区>

我在Eclipse中写了这个Java接口(interface)程序,但是在MyTriangle tmp = new MyTriangle();下面有一条红线,当我运行这个程序时,我得到了这个错误:

No enclosing instance of type Question1 is accessible. Must qualify the allocation with an enclosing instance of type Question1 (e.g. x.new A() where x is an instance of 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;
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com