在eclipse如何使用包,就是两个类不在一个包中,求教程,dos命令上会
在eclipse怎么使用包,就是两个类不在一个包中,求教程,dos命令下会
package MyPackage;
public class date
{
public int year; //访问权限设为public,以下同理
public int month;
public int day;
public date(int year,int month,int day)
{
this.year=year;
this.month=month;
this.day=day;
}
public void print()
{
System.out.println("日期是: "+year+"-"+month+"-"+day);
}
}
//测试类
import MyPackage.date;
public class hello4
{
public static void main(String[] args)
{
date r1=new date(2012,9,15);
r1.print();
}
}
------解决方案--------------------
你这样写可以了,在hello4中导入了MyPackage.date
只是hello4是属于哪个包的?你代码里没有它所在的包。
package MyPackage;
public class date
{
public int year; //访问权限设为public,以下同理
public int month;
public int day;
public date(int year,int month,int day)
{
this.year=year;
this.month=month;
this.day=day;
}
public void print()
{
System.out.println("日期是: "+year+"-"+month+"-"+day);
}
}
//测试类
import MyPackage.date;
public class hello4
{
public static void main(String[] args)
{
date r1=new date(2012,9,15);
r1.print();
}
}
------解决方案--------------------
你这样写可以了,在hello4中导入了MyPackage.date
只是hello4是属于哪个包的?你代码里没有它所在的包。
- Java code
package cn.com.mypackage; import MyPackage.date; public class hello4{ ....... }