【发布时间】:2015-01-12 14:19:10
【问题描述】:
没有访问说明符定义的类的访问范围是什么? 例如:
package com.foo.bar;
class MyFoo{
// All Class definition
}
我知道这样的类称为package class,与public class相对。所以我的问题是我们可以从哪里访问和使用此类(因为它们似乎无法从任何地方访问)。我可以从同一个包的另一个公共类访问它吗?
例如:
package com.foo.bar;
public class MyBar{
MyFoo foo; // Compiler throwing and error at this line
// Rest of definition
}
我已经问过谷歌,但没有得到回复。
【问题讨论】:
-
你导入了类吗?什么错误?
-
知道了。正如Task在回答中提到的那样,我缺少导入语句。因此编译器抛出一个错误说
cannot find symbol class MyFoo
标签: java access-modifiers