Quiz Space

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

Question 1: Consider the code given below. Choose the correct option.

Question 1

+4 marksOne correct option

Consider the code given below.

java
class Shared {
static int count = 2000;
}
class Subtractor extends Thread {
public void run() {
for (int i = 0; i < 1000; i++) {
Shared.count--;
}
}
}
public class Test {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Subtractor();
Thread t2 = new Subtractor();
t1.start();
t2.start();
t1.join();
t2.join();
System.out.print(Shared.count);
}
}

Choose the correct option.

  1. A

    The code always prints 2000.

  2. B

    The code prints any number in the range 1000 to 2000

  3. C

    The code prints any number in the range 0 to 1000

  4. D

    The code always prints 1000.

Show answer

Correct answer

  • C

    The code prints any number in the range 0 to 1000

Question 1 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. Q2Consider the following Java code that uses chained exceptions. Which of these could be the output of this code?
  2. Q3Consider the two Java files given below. Animal.java: Test.java: Choose the correct option.
  3. Q4Consider the Java code given below. Choose the correct option.
  4. Q5Consider the code given below. Choose the correct option.
  5. Q6Consider the Java code given below. What will the output be?
  6. Q7Consider the Java code given below. Choose the correct option.
  7. Q8Consider the Java code given below. What will the output be?
  8. Q9Consider the Java code given below. Choose the correct option.
  9. Q10The method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a fu…
  10. Q11Consider the code given below. What will the output be?
  11. Q12Method Optional.ofNullable(T value) returns an Optional describing the specified value, if non-null, otherwise returns …
  12. Q13Consider the code given below. What will the output be?
  13. Q14Consider the following Java code. Choose the correct option when the class is executed as:
  14. Q15Consider the Java code given below. Assume the file "data.txt" already contains the following text: All the best for ex…
  15. Q16Method Collectors.partitioningBy(predicate) returns a Collector which partitions the input elements according to a pred…
  16. Q17Figure question
  17. Q18Which of the following statements is/are correct regarding garbage collection?
  18. Q19Consider the Java code given below. Which of the following is true about the given code.
  19. Q20Consider the code given below. Which of the following options is/are possible result/s of the above code?
  20. Q21Consider the Java code given below that processes Displayable objects in a shop. From among the options, identify the a…
  21. Q22Consider the following Java code. Identify the line/s which has/have errors.
  22. Q23Consider the Java code given below.