Quiz Space

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

Question 1

+4 marksOne correct option

Consider the code given below.

java
class Shared {
static int count = 0;
}
class Adder 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 Adder();
Thread t2 = new Adder();
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 FileStorageException extends Exception {
public FileStorageException(String message) {
super(message);
}
}
class FileUploadException extends Exception {
public FileUploadException(String message) {
super(message);
}
}
class FileService {
public void uploadFile(String filename) throws FileUploadException {
try {
// if(do not have enough disk space to store the file)
throw new FileStorageException("Insufficient disk space");
// else upload the file
} catch (FileStorageException e) {
FileUploadException fue = new FileUploadException("Failed to upload");
fue.initCause(e);
throw fue;
}
}
}
public class FileApp {
public static void main(String[] args) {
FileService fileService = new FileService();
try {
fileService.uploadFile("report.pdf");
} catch (FileUploadException e) {
System.out.println(e.getMessage());
System.out.println("Reason: " + 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;
public class Animal {
private String name;
private String habitat;
private int legs;
// Constructor to initialize instance variables
public String getName(String name) {
return name;
}
protected String getHabitat(String habitat) {
return habitat;
}
private int getLegs(int legs) {
return legs;
}
public int showLegs(int legs) {
return getLegs(legs);
}
}

Test.java:

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

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 QDD1 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 13 Apr 2025, in the January 2025 term, set QDD1: 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 QDD1 at a glance
TermJanuary 2025 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ16
MSQ7
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