Quiz Space

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

Question 1

+4 marksOne or more correct options

Consider the following Java code.

java
1. class Fridge {
2. public final void cool() {
3. System.out.println("Cools the fridge");
4. }
5. }
6. class Compressor {
7. public final void start() {
8. System.out.println("Starts compressor");
9. }
10. }
11. class DoubleDoorFridge extends Fridge, Compressor {
12. public void cool() {
13. System.out.println("Cools the double door fridge");
14. }
15. }
16. public class Test {
17. public static void main(String[] args) {
18. DoubleDoorFridge f1 = new Fridge();
19. DoubleDoorFridge f2 = new Compressor();
20. }
21.}

Identify the line/s which has/have error.

Select all that apply.

  1. A

    Line 2

  2. B

    Line 7

  3. C

    Line 11

  4. D

    Line 12

  5. E

    Line 18

  6. F

    Line 19

Question 2

+4 marksOne or more correct options

Consider the Java code given below.

java
package week12;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class ButtonDemo extends JFrame implements ActionListener {
JButton btnGo, btnWait;
JLabel label;
JPanel p1, p2;
public ButtonDemo() {
p1 = new JPanel();
p2 = new JPanel();
btnGo = new JButton("Go");
btnWait = new JButton("Wait");
label = new JLabel("Click a button");
p1.add(btnGo);
p1.add(btnWait);
p2.add(label);
add(p1,"Center");
add(p2,"South");
btnGo.setActionCommand("Go");
btnWait.setActionCommand("Wait");
btnGo.addActionListener(this);
btnWait.addActionListener(this);
setSize(300, 150);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
//CODE SEGMENT
}
}
public class GUITest {
public static void main(String[] args) {
new ButtonDemo();
}
}

Choose the correct code segment to be filled inside method actionPerformed() such that on clicking the Go button, the label text changes to Going and on clicking the Wait button, the label text changes to Waiting.

Select all that apply.

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

Question 3

+5 marksOne or more correct options

Consider the code given below.

java
import java.util.concurrent.locks.ReentrantLock;
class Hotel {
int roomsAvailable = 5;
private final ReentrantLock lock = new ReentrantLock();
public void bookRoom(String cN, int rR) {
lock.lock();
try {
if (roomsAvailable >= rR) {
roomsAvailable -= rR;
System.out.println(cN + " successfully booked " + rR + "
rooms.");
} else {
System.out.println(cN + " cannot book " + rR + " rooms.");
}
} finally {
lock.unlock();
}
}
}
class HotelGuest implements Runnable {
Hotel hotel;
String customerName;
int roomsRequested;
// Constructor is defined here
public void run() {
hotel.bookRoom(customerName, roomsRequested);
}
}
public class HotelBooking {
public static void main(String[] args) throws InterruptedException {
Hotel hotel = new Hotel();
HotelGuest g1 = new HotelGuest(hotel, "Kiran", 3);
HotelGuest g2 = new HotelGuest(hotel, "Ameen", 4);
Thread t1 = new Thread(g1);
Thread t2 = new Thread(g2);
t1.start();
t2.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

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

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 22 Dec 2024, in the September 2024 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 22 Dec 2024 Set QDD3 at a glance
TermSeptember 2024 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MSQ4
MCQ19
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