该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.io.*;
import java.util.*;
public class Example515 {
private String name;
private Formatter f;
public Example515(String name,Formatter f)
{
this.name=name;
this.f=f;
}
public void move(int x,int y)
{
f.format("%s The turtle is at (%d,%d)\n", name,x,y);
}
public static void main(String[] args)
{
PrintStream outAlies=System.out;
Example515 tommy=new Example515("Tommy",new Formatter(System.out));
Example515 terry=new Example515("Terry",new Formatter(outAlies));
tommy.move(0,0);
terry.move(4,8);
}
}输出Tommy The turtle is at (0,0)
Terry The turtle is at (4,8)
而:package Chapter13;
import java.io.*;
import java.util.*;
public class Example515 {
private String name;
private Formatter f;
public Example515(String name,Formatter f)
{
this.name=name;
this.f=f;
}
public void move(int x,int y)
{
f.format("%s The turtle is at (%d,%d)\n", name,x,y);
}
public static void main(String[] args)
{
PrintStream outAlies=System.err;
Example515 tommy=new Example515("Tommy",new Formatter(System.err));
Example515 terry=new Example515("Terry",new Formatter(outAlies));
tommy.move(0,0);
terry.move(4,8);
}
}
输出
Tommy The turtle is at (0,0)
Terry The turtle is at (4,8)而且结果的哦颜色不一样!怎么回事?