当前位置: 技术问答>java相关
java 运行问题!
来源: 互联网 发布时间:2015-04-17
本文导语: package pg; class Number { int i; } public class Assignment extends java.lang.Object{ public static void main(String[] args) { Number n1 = new Number(); Number n2 = new Number(); n1.i = 9; n2.i = 47; System.out...
package pg;
class Number {
int i;
}
public class Assignment extends java.lang.Object{
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
n1.i = 9;
n2.i = 47;
System.out.println("1: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1 = n2;
System.out.println("2: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1.i = 27;
System.out.println("3: n1.i: " + n1.i +
", n2.i: " + n2.i);
}
}
当我不加 package pg;
javac Assignment
java Assignment
运行正常显示结果!
加入package pg;时该如何编译和运行。
谢谢!
class Number {
int i;
}
public class Assignment extends java.lang.Object{
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
n1.i = 9;
n2.i = 47;
System.out.println("1: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1 = n2;
System.out.println("2: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1.i = 27;
System.out.println("3: n1.i: " + n1.i +
", n2.i: " + n2.i);
}
}
当我不加 package pg;
javac Assignment
java Assignment
运行正常显示结果!
加入package pg;时该如何编译和运行。
谢谢!
|
新建pg,把Assignment.java放到pg目录下
|
java pg.Assignment