Thursday, August 12, 2010

Test your Java knowledge

What you think will be the output of the below code be?


class TestPrivate {
   private String s;
   public TestPrivate () {
      s = “Actual String”;
   }
   public void print() {
      System.out.println("S is: "+s);
   }
   public void change(TestPrivate tp) {
      tp.s = tp.s + ” Modified”;
   }
   public static void main (String args[]) {
      TestPrivate s1 = new TestPrivate ();
      TestPrivate s2 = new TestPrivate ();
      s1.print();
      s2.change(s1);
      s1.print();
   }
}

Blog Archive