Write the program in java and make sure to comment on each line Not applicable.
ID: 3854583 • Letter: W
Question
Write the program in java and make sure to comment on each line
Explanation / Answer
public class LockStyle {
public void method1(String o1,Integer o2) //method accept string and int
{
synchronized(o1)
{
System.out.println(o1); //print string
}
synchronized(o2)
{
System.out.println(o2);//print int
}
}
public void method2(String o1,Integer o2)//method accept string and int
{
synchronized(o2)
{
System.out.println(o2);//print int
}
synchronized(o1)
{
System.out.println(o1);//print string
}
}
public static void main(String[] args) {
LockStyle so=new LockStyle();//create object of classs
Thread t = new Thread(new Runnable() {//create thread
@Override
public void run() {
// Insert some method call here.
String s=new String("akshay");
Integer i=new Integer(123);
so.method1(s,i);
so.method2(s,i);
}
});
t.start();
}
}
==========================================
akshay
123
123
akshay
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.