【发布时间】:2014-10-08 20:16:52
【问题描述】:
我有以下两个类
package one;
public class Student
{
//Some code
}
package two;
public class Test
{
public static void main(String args[])
{
Student s = new Student();
//Some code
}
}
即使“Student”类具有公共访问修饰符,每当我尝试在来自另一个包的 Test 类中为 Student 类创建对象时,eclipse 都会指出错误,说我需要导入学生类或创建一个新类。
我想如果一个类被声明为公共的,它就可以从任何地方访问。但是为什么 eclipse 称它为错误呢?
【问题讨论】:
-
使用同一个包
-
使用完全限定名:
one.Student