Hi ,
I was trying to run the following code in which in the run method i have created another object of the same class(S) & through that i have called met method in that class. i dont understand why the code prints "hi" (in met method)infinitely.If instead of crating another object in run method,i write this.met then code prints "hi" only once.
Can anybody explain me why the code prints "hi " infinitely???
class S implements Runnable
{
S()
{
Thread t=new Thread(this);
t.start();
}
public void run()
{
S d=new S();
this.met();
}
synchronized void met()
{
System.out.println("hi");
}
}
class A
{
public static void main(
String[] args)
{
S s=new S();
}
};