当我在同一目录中创建基类和派生类而未指定任何包时,它们编译得很好,但将它们添加到包会导致派生类中出现错误,说它不能够发现他是基类的象征。这个错误是令人沮丧的,因为我之前一直在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