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

zhou2008zhou_zhou 2012-06-09 03:19:38
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.
...全文
83 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Edward1688 2012-06-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
你的路径没放对吧
package packagea的意思是你的student1这个类文件要放在以student类文件下的packagea文件夹里,而且你的class student1前要加public

在你的student类的目录下建一个packagea文件夹,把你的student1类文件放进去,然后先编译student1类,再编译student类,记得class student1前面要……
[/Quote]
++++
jlu_lamp_lamp 2012-06-09
  • 打赏
  • 举报
回复
你的路径没放对吧
package packagea的意思是你的student1这个类文件要放在以student类文件下的packagea文件夹里,而且你的class student1前要加public

在你的student类的目录下建一个packagea文件夹,把你的student1类文件放进去,然后先编译student1类,再编译student类,记得class student1前面要加public
zhou2008zhou_zhou 2012-06-09
  • 打赏
  • 举报
回复
好像不对啊!
Seanake 2012-06-09
  • 打赏
  • 举报
回复

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

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧