Code :
class Institute
{
synchronized public void classRoom( String facultyName )
{
for(int i=1;i<=10;i++)
{
System.out.println(i+". Class Taking By: "+facultyName);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
class MyThread extends Thread
{
Institute ins;
String facultyName;
@Override
public void run()
{
ins.classRoom(facultyName);
}
MyThread( Institute ins , String facultyName )
{
this.ins = ins;
this.facultyName = facultyName;
}
}
public class Test extends Thread
{
public static void main(String args[]) throws InterruptedException
{
Institute ins = new Institute();
MyThread mt1 = new MyThread(ins , "atharva");
MyThread mt2 = new MyThread(ins , "ramchandra");
mt1.start();
mt2.start();
}
}
{
synchronized public void classRoom( String facultyName )
{
for(int i=1;i<=10;i++)
{
System.out.println(i+". Class Taking By: "+facultyName);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
class MyThread extends Thread
{
Institute ins;
String facultyName;
@Override
public void run()
{
ins.classRoom(facultyName);
}
MyThread( Institute ins , String facultyName )
{
this.ins = ins;
this.facultyName = facultyName;
}
}
public class Test extends Thread
{
public static void main(String args[]) throws InterruptedException
{
Institute ins = new Institute();
MyThread mt1 = new MyThread(ins , "atharva");
MyThread mt2 = new MyThread(ins , "ramchandra");
mt1.start();
mt2.start();
}
}