1 public class StringBufferTest { 2 StringBuffer sb1; 3 StringBuffer sb2; 4 String s; 5 6 public StringBufferTest(String a, String b) { 7 sb1 = new StringBuffer(a); 8 sb2 = new StringBuffer(b); 9 s = a + b; 10 } 11 12 public static void main(String[] args) { 13 StringBufferTest test = new StringBufferTest("Hello ", "world"); 14 if (test.sb1.toString().equals("Hello ")) { 15 System.out.println("test.sb1.toString() correct: " + test.sb1.toString()); 16 } else { 17 System.err.println("test.sb1.toString() failed!"); 18 } 19 if (test.sb2.toString().equals("world")) { 20 System.out.println("test.sb2.toString() correct: " + test.sb2.toString()); 21 } else { 22 System.err.println("test.sb2.toString() failed!"); 23 } 24 if (test.s.equals("Hello world")) { 25 System.out.println("test.s correct: " + test.s); 26 } else { 27 System.err.println("test.s failed!"); 28 } 29 } 30 } 31 32 // vim: tabstop=4 expandtab shiftwidth=4