public class Oct11 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Test t = new Test(); System.out.println("t.i and t.j are " + t.getI() + " " + t.getJ()); String s1 = "abc"; // an interned string object String s2 = new String("abc"); // a different object String s3 = new String("abc"); // another object String s4 = "abc"; // the same interned string object as s1 String s5 = s3.intern();// the same interned string object as s1 String s6 = s4.intern();// the same interned string object as s1 System.out.println(s1 == s2); System.out.println(s1.equals(s2)); System.out.println(s3 == s2); System.out.println(s3.equals(s2)); System.out.println(s1 == s4); System.out.println(s1.equals(s4)); System.out.println(s1 == s5); System.out.println(s1.equals(s5)); System.out.println(s1 == s6); System.out.println(s1.equals(s6)); } } class Test{ private int i; private int j=i+1; // is initialized to 1 since i is initially 0 Test(){ i = 10; } public int getI(){ //int i = 20; // shadows instance variable i return i; } public int getJ(){ return j; } }