帮解释下这个JAVA程序

来源:百度知道 编辑:UC知道 时间:2024/07/04 02:42:33
class intergerSample
{
static int x;
static int y;
public int x(){
return x;
}
public void setX(int newX){
x=newX;
}
public int y(){
return y;
}
public void setY(int newY){
y=newY;
}
}
class staticSample
{
public static void main(String[] args)
{
intergerSample myXY=new intergerSample();
intergerSample anotherXY=new intergerSample();
myXY.setX(1);
anotherXY.x=2;
myXY.setY(1);
anotherXY.y=2;
System.out.println("myXY.x="+myXY.x());
System.out.println("anotherXY.x="+anotherXY.x());
System.out.println("myXY.y="+myXY.y());
System.out.println("anotherXY.y="+anotherXY.y());
}
}

请帮忙解释一下,重点在于MAIN下面的;

================================================================
另找JAVA或是C的沈阳实习地方

class intergerSample
{
static int x;
static int y;
(这一部分表示在intergerSample 这个object中 有两个静态域 x 和 y )
(静态域表示在所有object共享同一个域,一个object的x 和 y 改变, 那么所有 object的x 和 y 都改变了)

public int x(){
return x;
}
(一个方法, 返回x的值)
public void setX(int newX){
x=newX;
}
(一个方法,设定x的值)
public int y(){
return y;
}
(一个方法,返回y的值)
public void setY(int newY){
y=newY;
}
(一个方法,设定y的值)
}

class staticSample
{
public static void main(String[] args)
{
intergerSample myXY=new intergerSample();
(建立一个叫做myXY 的intergerSample 类型的object)

intergerSample anotherXY=new intergerSample();
(建立一个叫做anotherXY 的intergerSample 类型的object)

myXY.setX(1);
(把myXY的x值设为1,因为x是static的,所以anotherXY的x 也变成了 1)
anotherXY.x=2;
(把anotherXY的x值设为2,因为x是static的,所以myrXY的x 也变成了 2)
myXY.setY(1);
(把myXY的y值设为1,因为y是static的,所以anotherXY的y