[問題] class的一個小問題
剛剛在測試
打了這串程式碼
public class testcode
{
class test
{
double hight;
double width;
void area()
{
System.out.println("面積是:");
double ans = (hight*width);
System.out.println(ans);
}
}
public static void main( String args [])
{
test a=new test();
a.hight = 10;
a.width = 10;
a.area();
}
}
出現以下的錯誤
non-static variable this cannot be referenced from a static context
test a=new test();
^
我仔細的跟書上寫的對照了好幾次 就是不知道到底哪裡出錯@@"
請大家幫幫忙
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.213.144
推
03/05 19:20, , 1F
03/05 19:20, 1F
→
03/05 19:24, , 2F
03/05 19:24, 2F
→
03/05 19:30, , 3F
03/05 19:30, 3F
推
03/05 20:31, , 4F
03/05 20:31, 4F
推
03/05 20:36, , 5F
03/05 20:36, 5F
→
03/05 20:38, , 6F
03/05 20:38, 6F
推
03/05 20:42, , 7F
03/05 20:42, 7F
推
03/05 20:43, , 8F
03/05 20:43, 8F
推
03/05 20:52, , 9F
03/05 20:52, 9F
推
03/05 23:59, , 10F
03/05 23:59, 10F
推
03/06 00:56, , 11F
03/06 00:56, 11F