物件導向 用類別建立一個新的變數

本來是用日食寫 可是在CMD下無法找到其他CLASS

所以想要把它寫在一起 就出現下面的問題

Multiple markers at this line

- Rcat cannot be resolved to a variable

- No enclosing instance of type CMDTest is accessible. Must qualify the allocation with an

enclosing instance of type CMDTest (e.g. x.new A() where x is an instance of CMDTest).

這是程式碼

public class CMDTest {

public static void main(String[] args) {

Rcat c1=new Rcat();

c1.display();

}

public abstract class Cat{public void display() {}}

class Rcat extends Cat{public void display()

{System.out.print(" Rcat ");}}

}

Update:

可以了 謝謝 那如果我有很多的CLASS 也是要一樣寫在同一個檔案裡面嗎?

1 Answer

Rating
  • 薩秋
    Lv 5
    1 decade ago
    Favorite Answer

    把Cat 類別與Rcat 類別搬出去就好。

    public class CMDTest{

    ...

    }

    abstract class Cat{

    ...

    }

    class Rcat extends Cat{

    ...

    }

    2010-10-05 09:18:10 補充:

    為了維持好的撰寫習慣,

    最好是一個類別一個檔案啦,

    當然你想全部寫在一個也是可以ㄚ@@...

Still have questions? Get your answers by asking now.