<![CDATA[abc
主题无关行
]]>

解决方案 »

  1.   

    测试xml
    <![CDATA[abc
    主题无关行
    ]]>
      

  2.   

    public class Bath {
    private String
    // Initializing at point of definition:
    s1 = new String("Happy"),
    s2 = "Happy",//...........1
    s3,s4;//..........2
    Soap castille;
    int i;
    float toy;
    Bath() {
    System.out.println("Inside Bath()");
    s3 = new String("Joy");
    i = 47;
    toy = 3.14f;
    castille = new Soap();
    }
    void print() {
    // Delayed initialization:
    if(s4 == null)
    s4 = new String("Joy");//...........3
    System.out.println("s1 = " + s1);
    System.out.println("s2 = " + s2);
    System.out.println("s3 = " + s3);
    System.out.println("s4 = " + s4);
    System.out.println("i = " + i);
    System.out.println("toy = " + toy);
    System.out.println("castille = " + castille);
    }
    public static void main(String[] args) {
    Bath b = new Bath();
    b.print();
    }
    }///:~
    因为castille是个类,直接打印时,他会调用自己的toString()方法,转成字符串输出
    该例中,就是返回了s,
      

  3.   

    请注意,我问的是object reference 的组合问题,不是s1等。
    对于toString()方法,下例为何无法打印?
    //:c06:SprinklerSystem.java
    // Composition for code reuse.class WaterSource {
    private String s;
    WaterSource() {
    System.out.println("WaterSource()");
    s = new String("Constructed");
    }
    public String toString() { return s; }
    }public class SprinklerSystem {
    private String valve1,valve2,valve3,valve4;
    WaterSource source;
    int i;
    float f;
    void print() {
    System.out.println("valve1 = " + valve1);
    System.out.println("valve2 = " + valve2);
    System.out.println("valve3 = " + valve3);
    System.out.println("valve4 = " + valve4);
    System.out.println("i = " + i);
    System.out.println("f = " + f);
    System.out.println("source = " + source);
    }
    public static void main(String[] args) {
    SprinklerSystem x = new SprinklerSystem();
    x.print();
    }
    }///:~输出结果:
    valve1 = null
    valve2 = null
    valve3 = null
    valve4 = null
    i = 0
    f = 0.0
    source = null  (此处为什么不输出"WaterSource" 和 "Constructed"?)请高手指教!
      

  4.   

    class WaterSource {
    private String s;
    WaterSource() {
    System.out.println("WaterSource()");
    s = new String("Constructed");
    }
    public String toString() { return s; }
    }public class SprinklerSystem {
    private String valve1,valve2,valve3,valve4;
    WaterSource source=new WaterSource(); // **要让引用指向一个对象
    int i;
    float f;
    void print() {
    System.out.println("valve1 = " + valve1);
    System.out.println("valve2 = " + valve2);
    System.out.println("valve3 = " + valve3);
    System.out.println("valve4 = " + valve4);
    System.out.println("i = " + i);
    System.out.println("f = " + f);
    System.out.println("source = " + source);
    }
    public static void main(String[] args) {
    SprinklerSystem x = new SprinklerSystem();
    x.print();
    }
    }///:~你在定义source的时候,仅仅是定义了该对象的一个引用,并未真正创建一个类的实例
    因此没有调用WaterSource的构造函数,必须改为WaterSource source=new WaterSource(); 
      

  5.   

    java只帮你初始化基本数据类型的成员,如:int, boolean.这种基本的数据类型不是从Object中继承。