Quiz Space

Java End Term: 13 April 2025, Set QDD3 (January 2025 term)

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.

Question 2

+4 marksOne correct option

Consider the following Java code that uses chained exceptions.

java
class PaymentException extends Exception {
public PaymentException(String message) {
super(message);
}
}
class OrderProcessingException extends Exception {
public OrderProcessingException(String message) {
super(message);
}
}
class OrderService {
public void placeOrder() throws OrderProcessingException {
try {
// if(payment fails)
throw new PaymentException("Payment not done");
// else process the order
} catch (PaymentException e) {
OrderProcessingException oe = new OrderProcessingException
("Order Failed");
oe.initCause(e);
throw oe;
}
}
}
public class Test {
public static void main(String[] args) {
OrderService orderService = new OrderService();
try {
orderService.placeOrder();
} catch (OrderProcessingException e) {
System.out.println(e.getMessage());
System.out.println("Root cause: " + e.getCause().getMessage());
}
}
}

Which of these could be the output of this code?

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

Question 3

+4 marksOne correct option

Consider the two Java files given below.

Animal.java:

java
package creatures;
class Animal {
private String name;
private String habitat;
private int legs;
// Constructor to initialize instance variables
public String getName(String name) {
return name;
}
private String getHabitat(String habitat) {
return habitat;
}
protected int getLegs(int legs) {
return legs;
}
public int showLegs(int legs) {
return getLegs(legs);
}
}
class Bird extends Animal {
public void info() {
System.out.println("This is a Bird.");
}
public void displayHabitat() {
System.out.println("Bird's habitat: " + getHabitat("Trees"));
}
}

Test.java:

java
package creatures;
public class Test {
public static void main(String[] args) {
Animal myAnimal = new Animal();
System.out.println("Number of legs: " + myAnimal.showLegs(4));
System.out.println(myAnimal.getHabitat("Forest")); // LINE 1
System.out.println(myAnimal.getLegs(4)); // LINE 2
}
}

Choose the correct option.

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

20 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Java End Term 13 Apr 2025 Set QDD3 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 13 Apr 2025, in the January 2025 term, set QDD3: 23 questions for 100 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureJava End Term 13 Apr 2025 Set QDD3 at a glance
TermJanuary 2025 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ17
MSQ6
Official paperIIT M DIPLOMA AN EXAM QDD3 13 Apr 2025
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java