Question 18
Consider the following code
class BookingEnquiry{ int available = 1; public synchronized void request(int n, String name){ if(available >= n){ available = available - n; System.out.println(name + " booked " + n + " ticket"); } else{ System.out.println(name + " cannot book " + n + " ticket"); } }}class TicketBooking implements Runnable{ BookingEnquiry e; String name; int n_tickets; public TicketBooking(BookingEnquiry e1, String n, int t){ e = e1; name = n; n_tickets = t; } public void run(){ e.request(n_tickets, name); }}public class ThreadTest { public static void main(String[] args) { BookingEnquiry obj = new BookingEnquiry(); TicketBooking tb1 = new TicketBooking(obj, "Shannu", 1); TicketBooking tb2 = new TicketBooking(obj, "Karthik", 1); Thread t1 = new Thread(tb1); Thread t2 = new Thread(tb2); t1.start(); t2.start(); }}Which of the following is/are possible output(s)?
Shannu booked 1 ticket
Karthik booked 1 ticketKarthik booked 1 ticket
Shannu booked 1 ticketShannu booked 1 ticket
Karthik cannot book 1 ticketKarthik booked 1 ticket
Shannu cannot book 1 ticketKarthik cannot book 1 ticket
Shannu cannot book 1 ticketShannu cannot book 1 ticket
Karthik cannot book 1 ticket