[問題] 為甚麼 class 無法 new?
我把程式很精簡化了
就下面這樣
卻還是不能COMPILER
但是我把●●●這行刪掉 就可以
奇怪
這樣為什麼不對?
public class PetDemo
{
public static void main(String[] args)
{
Pet usersPet = new Pet();●●●●●●●●●●●●●●●
}
public class Pet
{
private int age;
}
}
錯誤訊息
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type PetDemo is accessible.
Must qualify the allocation with an enclosing instance of
type PetDemo (e.g. x.new A() where x is an instance of PetDemo).
at PetDemo.main(PetDemo.java:5)
我是照著課本範例然後取我不能編譯的地方PO上來
都照課本還不能編譯好奇怪.....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.104.179.182
※ 編輯: locaa 來自: 112.104.179.182 (05/13 02:55)
推
05/13 03:14, , 1F
05/13 03:14, 1F
→
05/13 03:16, , 2F
05/13 03:16, 2F
→
05/13 03:30, , 3F
05/13 03:30, 3F
→
05/13 03:33, , 4F
05/13 03:33, 4F
推
05/13 06:05, , 5F
05/13 06:05, 5F
推
05/13 08:08, , 6F
05/13 08:08, 6F
→
05/13 08:35, , 7F
05/13 08:35, 7F
→
05/13 08:53, , 8F
05/13 08:53, 8F
→
05/13 09:39, , 9F
05/13 09:39, 9F
→
05/13 12:10, , 10F
05/13 12:10, 10F
→
05/13 12:11, , 11F
05/13 12:11, 11F
推
05/13 14:20, , 12F
05/13 14:20, 12F
推
05/17 02:40, , 13F
05/17 02:40, 13F
java 近期熱門文章
3
14
PTT數位生活區 即時熱門文章