这是我第一个Package 包相关类的测试例子,分为三部分:MainTest 、PackageSecond 和PackageSub
1。MainTest
路径:PackageTest\com\xzm\maintest
package com.xzm.maintest;
import com.xzm.pksub.*;
import com.xzm.pksecond.*;
public class Main
{
public static void main(String[] args)
{
PackageSecond second = new PackageSecond("I am in Main");
second.printvalue();
PackageSub sub = new PackageSub("I am in Main");
sub.printvalue();
System.exit(0);
}
}
2。PackageSecond
路径:PackageTest\com\xzm\pksecond
package com.xzm.pksecond;
public class PackageSecond
{
private String value;
public PackageSecond(String s)
{
value = s;
}
public void printvalue()
{
System.out.println("value of PackageSecond is " + value);
}
}
3。PackageSub
路径:PackageTest\com\xzm\pksub
package com.xzm.pksub;
import com.xzm.pksecond.*;
public class PackageSub
{
private String value;
public PackageSub(String s)
{
value = s;
}
public void printvalue()
{
PackageSecond second = new PackageSecond("I am in subpackage.");
second.printvalue();
System.out.println("value of PackageSub is " + value);
}
}