? asked in 電腦與網際網路程式設計 · 1 decade ago

我寫的計算面積怪怪的(用到interface)

interface basic

{

final int length = 10;

public abstract int show();

}

class square implements basic

{

public int show()

{

System.out.println("square");

return length * length;

}

}

class cube implements baisc

{

public int show()

{

System.out.println("cube");

return length * length * 6;

}

}

public class test

{

public static void main(String args[])

{

basic a;

a = new square();

System.out.println(a.show());

a = new cube();

System.out.println(a.show());

}

}

Update:

沒亂碼的

http://www.wretch.cc/blog/aknro/32364492

為什麼會找不到變數length呢?

我在interface裡面已經宣告了阿

3 Answers

Rating
  • 1 decade ago
    Favorite Answer

    class cube implements baisc

    baisc 改成 basic....

    就正常了QQ

    P.S.測試之後好像沒有讀不到的問題

    Source(s): 自己
  • 胤煌
    Lv 5
    1 decade ago

    class cube implements baisc 改成 class cube implements basic

    單純的拼錯單字而已

  • Samuel
    Lv 5
    1 decade ago

    這一行打錯字了:

    class cube implements baisc <------ basic 才對吧

Still have questions? Get your answers by asking now.