这是我java环境变量设置
path=%JAVA_HOME%\BIN
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_02
CLASSPATH=.;%JAVA_HOME%\jre\lib\rt.jar; %JAVA_HOME%\lib\dt.jar; %JAVA_HOME%\lib\tools.jar; 估计没问题这是我写的一个包, 放在C盘:
package Mypackage;
import java.io.*;public class Print
{
public static void print (Object obj)
{
System.out.println (obj);
}

public static void pirnt ()
{
System.out.println ();
}

public static void printnb (Object obj)
{
System.out.print (obj);
}

public static PrintStream

printf (String format, Object...args)
{

return System.out.printf (format, args);
}
}在 CLASSPATH 里加上:C:\Mypackage; 
调用这个包:(同样放在C盘)
import Mypackage.Print;class jav
{
public static void main (String args[])
{

print ("welcome to java world!");
}
}但是始终出错.
还一个问题。
另外一个包:C盘
package Mypackage;
import java.util.*; 

public class NewDate 
{
private int year,month,day;
public NewDate(int y,int m,int d)
{
year = y;
month = (((m>=1) & (m<=12)) ? m : 1);
day = (((d>=1) & (d<=31)) ? d : 1);

public NewDate()

this(0,0,0);

public static int thisyear() //获得当年的年份

return Calendar.getInstance().get(Calendar.YEAR);
}
public int year() //获得年份

return year;
}
public String toString() //转化为字符串
{
return year+"-"+month+"-"+day;
}
}调用这个包: C盘
import Mypackage. NewDate; //引用Mypackage包中的NewDate类
public class People
{
private String name;
private NewDate birth; public static void main(String args[])
{
People a = new People("Wangli",1981,2,14);
a.output();

public People(String n1,NewDate d1)
{
name = n1;
 birth = d1;
  }
public People(String n1,int y,int m,int d)
{
  this(n1,new NewDate(y,m,d));
  }
  public People()
{
 this("",new NewDate());
}
public int age() //计算年龄
{
 return NewDate.thisyear() - birth.year(); //获得年份
}
public void output()
{
  System.out.println("name : "+name);
  System.out.println("birth: "+birth.toString());
  System.out.println("age : "+age());

}
没有错误(没有在classpath后加环境变量)这是为什么??

解决方案 »

  1.   

    这样弄是不是麻烦些?我通常在 eclipse 下进行 package 设置,自动建立路径,无需到 classpath 中指定。按道理,Package mypackage.print 也应该有一个 print 子目录,不知道你是否注意到了?这个用 eclipse 很容易发现的。
      

  2.   

    楼主还要好好学习下java的变成规范,对命名的部分,提示:包名应该全小些
      

  3.   

    import Mypackage.Print; class jav 

    public static void main (String args[]) 
    { print ("welcome to java world!"); 

    }但是始终出错. 
    ------------------------static 
    Print.print(String );
      

  4.   

    问题在这哩
    print ("welcome to java world!"); 
    你没初始化对象就想调用啊
    4楼已经给出答案了,和包应该没啥大关系。
    另外,代码贴的太乱了,以后可以检些关键的贴,出了我这种特想挣分的人,估计没人会耐着性子看完,o(∩_∩)o...