New
| -- test
| -- Second.java
| -- Second.class
| -- com
| -- mypack
| -- First.java
| -- classes
| -- expecting First.class HERE
//Second Class
public class Second{}
//First Class
package com.mypack; // Problem HERE
public class First{
public static void main(String args[]){ new Second() };
}
案例 1:在 First class 中注释的 package 语句
C:\Anshul\New\com\package>javac -cp ..\..\test First.java
C:\Anshul\New\com\package>java -cp ..\..\test;. First
Second@19821f
-------------------------------------------------------------------------------------
案例 2:头等舱中未注释的包语句
C:\Anshul\New\com\mypack>javac -cp ..\..\test -d ..\..\classes First.java
First.java:7: cannot find symbol
symbol : class Second
location: class com.mypack.First
System.out.print(new Second());
^
1 error
---------------------------------------------------------------------------------
案例 1 运行良好。但是当我在 First 类中包含 package 语句并尝试编译它时会出错。