class Foo{
private int x;
public Foo(int x ){this.x = x;}
public void setX(int x ) {this.x = x;}
public int getX(){return x ;}
}
public class SubMit{
static Foo fooBar(Foo foo){ //这句话什么意思?
foo = new Foo(100);
return foo;
}
public static void main(String[] args){
Foo foo = new Foo(300);
System.out.print(foo.getX()+"-");
Foo fooFoo = fooBar(foo); //这句话什么意思?
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX()+"-");
foo = fooBar(fooFoo); //这句话什么意思?
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX());
}
}
private int x;
public Foo(int x ){this.x = x;}
public void setX(int x ) {this.x = x;}
public int getX(){return x ;}
}
public class SubMit{
static Foo fooBar(Foo foo){ //这句话什么意思?
foo = new Foo(100);
return foo;
}
public static void main(String[] args){
Foo foo = new Foo(300);
System.out.print(foo.getX()+"-");
Foo fooFoo = fooBar(foo); //这句话什么意思?
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX()+"-");
foo = fooBar(fooFoo); //这句话什么意思?
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX());
}
}
//省略了限定符的静态方法,此法定义了一个有一个参数,其类型为Foo类,返回一个Foo类的方法fooBar
//其实这就是一般的方法,只不过参数类型和返回类型是一个类而已,下面的几句就不用解释了吧
foo = new Foo(100);
return foo;
}
public static void main(String[] args){
Foo foo = new Foo(300);
System.out.print(foo.getX()+"-");
Foo fooFoo = fooBar(foo); //这句话什么意思?
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX()+"-");
foo = fooBar(fooFoo); //这句话什么意思?
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX());
}
}
class Foo{
private int x;
public Foo(int x ){this.x = x;}
public void setX(int x ) {this.x = x;}
public int getX(){return x ;}
}
public class SubMit{
static Foo fooBar(Foo foo){ //这句话是静态代码块。程序一运行到这里就会把这段代码加载到内存的静态代码区里,在这里相当于SubMit的一个方法。
foo = new Foo(100);
return foo;
}
public static void main(String[] args){
Foo foo = new Foo(300);
System.out.print(foo.getX()+"-");
Foo fooFoo = fooBar(foo); //这句话是相当于调用fooBar方法。
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX()+"-");
foo = fooBar(fooFoo); //这句话是上面那个类构造方法。
System.out.print(foo.getX()+"-");
System.out.print(fooFoo.getX());
}
}