Quiz Space

Java End Term: 22 December 2024, Set QDF1 (September 2024 term)

Question 1

+5 marksOne correct option

Consider the Java code given below, and answer the question that follows:

java
abstract class Operation implements Runnable {
static int total = 10;
}
class Operation1 extends Operation {
public void run() {
if (total != 8) {
total = total - 3;
}
}
}
class Operation2 extends Operation {
public void run() {
if (total != 7) {
total = total - 2;
}
}
}
public class RaceConditionDecrement {
public static void main(String[] args) {
Operation op1 = new Operation1();
Operation op2 = new Operation2();
Thread t1 = new Thread(op1);
Thread t2 = new Thread(op2);
t1.start();
t2.start();
System.out.println(Operation.total);
}
}

Choose the correct option.

  1. A

    The program will never generate the output: 5

  2. B

    The program will never generate the output: 7

  3. C

    The program will never generate the output: 8

  4. D

    The program will never generate the output: 10

  5. E

    The output can be 5 or 7 or 8 or 10.

Question 2

+5 marksOne correct option

Consider the code given below.

java
class Beverage {
public void ingredients() {
System.out.println("Basic ingredients");
}
public void price() {
System.out.println("Price not set");
}
}
class Coffee extends Beverage {
public void ingredients() {
System.out.println("Contains coffee beans and water");
}
public void price() {
System.out.println("Price: 100");
}
}
class Latte extends Coffee {
public void ingredients() {
System.out.println("Contains coffee beans, milk, and water");
}
public void maker() {
System.out.println("Makes latte");
}
}
public class BeverageTest {
public static void main(String[] args) {
Coffee drink = new Latte(); // LINE 1
drink.ingredients();
drink.price();
drink.maker(); // LINE 2
}
}

Choose the correct option.

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

Question 3

+5 marksOne correct option

Consider the following Java code that uses chained exceptions.

java
class FileProcessingException extends Exception {
public FileProcessingException(String message) {
super(message);
}
}
class InvalidFileFormatException extends Exception {
public InvalidFileFormatException(String message) {
super(message);
}
}
public class FileExceptionTest {
public static void main(String[] args) {
try {
processFile();
} catch (FileProcessingException e) {
System.out.println(e.getMessage());
System.out.println(e.getCause().getMessage());
}
}
public static void processFile() throws FileProcessingException {
try {
validateFile();
} catch (InvalidFileFormatException e) {
FileProcessingException fpe = new FileProcessingException("Error
processing file");
fpe.initCause(e);
throw fpe;
}
}
public static void validateFile() throws InvalidFileFormatException {
throw new InvalidFileFormatException("File format not supported");
}
}

What is the output of this code?

  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 22 Dec 2024 Set QDF1 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 22 Dec 2024, in the September 2024 term, set QDF1: 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 22 Dec 2024 Set QDF1 at a glance
TermSeptember 2024 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ19
MSQ4
Official paperIIT M FOUNDATION DIPLOMA FN EXAM QDF1 22 Dec 2024
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java