Dude....havent read the question....but from your code example i can say the following will give the desired output:--
public class stringTest implements Runnable{
private StringBuffer fer;
public synchronized void run()
{
{
for(int i=0;i<15;i++)
{
System.out.println(Thread.currentThread().getName()+"Letter = "+fer);
}
char f=fer.charAt(0);
char g=(char)(f+1);
fer.setCharAt(0,g);
}
}
public stringTest(StringBuffer der)
{
fer=der;
}
public static void main (
String args[])
{
StringBuffer de=new StringBuffer("a");
stringTest s=new stringTest(de);
Thread t1 = new Thread(s);
Thread t2 = new Thread(s);
Thread t3 = new Thread(s);
t1.setName("First");
t2.setName("Second");
t3.setName("Third");
t1.start();
t2.start();
t3.start();
}
}
Here we have only one stringTest object and 3 threads accessing it.
So now the synchronization comes in play.