1 public class StringTest { 2 private String s; 3 private String s2 = new String("abc"); 4 private static String s3; 5 public static String s4 = new String("xyz"); 6 7 public StringTest() { 8 s = s2; 9 } 10 11 public StringTest(String newString) { 12 s = newString; 13 } 14 15 public StringTest(String firstString, String secondString) { 16 s = firstString + secondString; 17 } 18 19 public static void main(String[] args) { 20 if (StringTest.s4.equals("xyz")) { 21 System.out.println("StringTest.s4 correct: " + StringTest.s4); 22 } else { 23 System.err.println("StringTest.s4 failed!"); 24 } 25 StringTest test0 = new StringTest(); 26 if (test0.s.equals("abc")) { 27 System.out.println("test0.s correct: " + test0.s); 28 } else { 29 System.err.println("test0.s failed!"); 30 } 31 StringTest test1 = new StringTest("Test"); 32 if (test1.s.equals("Test")) { 33 System.out.println("test1.s correct: " + test1.s); 34 } else { 35 System.err.println("test1.s failed!"); 36 } 37 StringTest test2 = new StringTest("Hello ", "world"); 38 if (test2.s.equals("Hello world")) { 39 System.out.println("test2.s correct: " + test2.s); 40 } else { 41 System.err.println("test2.s failed!"); 42 } 43 } 44 } 45 46 // vim: tabstop=4 expandtab shiftwidth=4