日期:2014-05-20  浏览次数:20684 次

新手,有关java中的包!请教高手啊!
package packagea;

class student1
{
  public int a=10;
  public void setPrint()
  {  
System.out.println("a="+a);
  }
}


import packagea.student1;

public class student
{
  public static void main(String args[])
  {
student1 stu=new student1();
stu.setPrint();
  }
}

为什么调试不出来呢!
结果总是:需要为class、interface或enum.

------解决方案--------------------

Java code
package packagea;
import packagea.student1;
包应写在第一行
import语句随其后

------解决方案--------------------
你的路径没放对吧
package packagea的意思是你的student1这个类文件要放在以student类文件下的packagea文件夹里,而且你的class student1前要加public 

在你的student类的目录下建一个packagea文件夹,把你的student1类文件放进去,然后先编译student1类,再编译student类,记得class student1前面要加public
------解决方案--------------------
探讨
你的路径没放对吧
package packagea的意思是你的student1这个类文件要放在以student类文件下的packagea文件夹里,而且你的class student1前要加public

在你的student类的目录下建一个packagea文件夹,把你的student1类文件放进去,然后先编译student1类,再编译student类,记得class student1前面要……