Quiz Space

Programming Concepts using Java · End Term · 13 Apr 2025 · January 2025 term · Set QDD1

Question 19: Consider the code given below. Which of the following op…

Question 19

+4 marksOne or more correct options

Consider the code given below.

java
class Library {
private boolean isBookAvailable = true;
public synchronized void borrowBook(String readerName) {
if (isBookAvailable) {
System.out.println(readerName + " borrowed the book.");
isBookAvailable = false;
} else {
System.out.println(readerName + " could not borrow the book.");
}
}
}
class Reader implements Runnable {
private Library library;
private String readerName;
public Reader(Library lib, String rn) {
this.library = lib;
this.readerName = rn;
}
public void run() {
library.borrowBook(readerName);
}
}
public class Test {
public static void main(String[] args) {
Library library = new Library();
Thread reader1 = new Thread(new Reader(library, "Rahul"));
Thread reader2 = new Thread(new Reader(library, "Ram"));
Thread reader3 = new Thread(new Reader(library, "Raghu"));
reader1.start();
reader2.start();
reader3.start();
}
}

Which of the following options is/are possible result/s of the above code?

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • A
  • C

Question 19 of 23 in the IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 13 Apr 2025, in the January 2025 term (IIT M DIPLOMA AN EXAM QDD3 13 Apr 2025). It carries 4 marks.

More questions from this paper

  1. Q1Consider the code given below. Choose the correct option.
  2. Q2Consider the following Java code that uses chained exceptions. Which of these could be the output of this code?
  3. Q3Consider the two Java files given below. Animal.java: Test.java: Choose the correct option.
  4. Q4Consider the following Java code. Choose the correct option when the class is executed as:
  5. Q5Consider the Java code given below. Choose the correct option.
  6. Q6Consider the Java code given below. What will the output be?
  7. Q7Consider the Java code given below. Choose the correct option.
  8. Q8Consider the Java code given below. What will the output be?
  9. Q9Consider the Java code given below. Choose the correct option.
  10. Q10Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a functi…
  11. Q11Consider the code given below. What will the output be?
  12. Q12Method Optional.ofNullable(T value) returns an Optional describing the specified value, if non-null, otherwise returns …
  13. Q13Consider the code given below. What will the output be?
  14. Q14Consider the Java code given below. Assume the file "data.txt" already contains the following text: Welcome to Java Pro…
  15. Q15Method Collectors.partitioningBy(predicate) returns a Collector which partitions the input elements according to a pred…
  16. Q16Consider the Java code given below.
  17. Q17Which of the following statements is/are correct?
  18. Q18Consider the Java code given below. Which of the following is/are true about the given code.
  19. Q20Consider the Java code given below that processes Drawable objects. From among the options, identify the appropriate fu…
  20. Q21Consider the code given below. Choose the correct option(s).
  21. Q22Consider the following Java code. Identify the line/s which has/have errors.
  22. Q23Consider the Java code given below.