Programming Concepts using Java, End Term
Consider the following Java code.
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.
Consider the following Java code. 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. Consider the Java code given below. 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`. Figure from the original question paper Consider the code given below. 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?