[Java 教學範例拷貝]- 套件(package)
[Java 教學範例拷貝]- 套件(package)
剛才找資料時發現一個的Java 教學網站,趕快發揮(C/P)的長才將它備份來,有需要的同好,歡迎來(C/P)一下^^。
拷貝來源:
http://openhome.cc/Gossip/JavaGossip-V1/
http://openhome.cc/Gossip/JavaGossip-V1/Package.htm
package onlyfun.caterpillar;
public class UsePackage {
public static void main(String[] args) {
System.out.println("Hello! World!");
}
}
package onlyfun.caterpillar;
public class Point2D {
private int x, y;
public Point2D() {x = 0; y = 0;}
public Point2D(int x, int y) {this.x = x; this.y = y;}
public int getX() {return x;}
public int getY() {return y;}
}
public class UsePackage {
public static void main(String[] args) {
onlyfun.caterpillar.Point2D p1 = new
onlyfun.caterpillar.Point2D(10, 20);
System.out.printf("p1: (x, y) = (%d, %d)%n",
p1.getX(), p1.getY());
}
}
import onlyfun.caterpillar.Point2D;
public class UsePackage {
public static void main(String[] args) {
Point2D p1 = new Point2D(10, 20);
System.out.printf("p1: (x, y) = (%d, %d)%n",
p1.getX(), p1.getY());
}
}
import onlyfun.caterpillar.*;
public class UsePackage {
public static void main(String[] args) {
Point2D p1 = new Point2D(10, 20);
System.out.printf("p1: (x, y) = (%d, %d)%n",
p1.getX(), p1.getY());
}
}
|