當我在同一目錄中創建基類和派生類而未指定任何包時,它們編譯得很好,但將它們添加到包會導致派生類中出現錯誤,說它不能夠發現他是基類的象徵。這個錯誤是令人沮喪的,因爲我之前一直在c中工作,爲什麼所有這些在Java中使用shenanigans呢?包中的基類和派生類
package Testpackage; // If I comment this then derived class compiles fine
public class Test_class{
int x,y;
public static Integer angle;
public Test_class(int a,int b)
{
x = a;
y = b;
}
public Integer product()
{
return x*y;
}
}
*************Derived class ****************
package Testpackage; // If I comment this then it compiles fine
public class Derived_class extends Test_class{
Integer vol;
Test_class I = new Test_class(1,2);
public Derived_class(){
super(9,10);
vol = 0;
}
public Integer volume()
{
vol = this.product();
return vol;
}
}
********* output *************
[email protected]:~/Testpackage$ javac Derived_class.java
Derived_class.java:4: cannot find symbol
symbol: class Test_class
public class Derived_class extends Test_class{
^
Derived_class.java:7: cannot find symbol
symbol : class Test_class
location: class Testpackage.Derived_class
Test_class I = new Test_class(1,2);
^
Derived_class.java:7: cannot find symbol
symbol : class Test_class
location: class Testpackage.Derived_class
Test_class I = new Test_class(1,2);
^
Derived_class.java:15: cannot find symbol
symbol : method product()
location: class Testpackage.Derived_class
vol = this.product();
是TestPackage你自己的包還是它提供的一些API來允許你測試你的代碼? – palAlaa 2011-02-06 03:53:03