Quiz Space

Programming Concepts using Java · Quiz 2 · 23 Nov 2025 · September 2025 term

Question 6: Consider the Java code given below.\ interface Discount{\…

Question 6

+7 marksOne correct option

Consider the Java code given below.
interface Discount{
public void apply(int price);
}
class ShoppingCart{
public Discount getDiscount(String type){
Discount d = null;
if(type == "festival")
d = new FestivalDiscount();
return d;
}
private class FestivalDiscount implements Discount{
public void apply(int price){
System.out.println("Final Price: " + (price - 100));
}
}
}
public class CartTest {
public static void main(String[] args) {
// CODE SEGMENT //
disc.apply(500);
}
}
Choose the correct option to fill in at CODE SEGMENT such that the output is:
Final Price: 400

  1. A

    FestivalDiscount disc = new ShoppingCart().getDiscount("festival");

  2. B

    Discount disc = new ShoppingCart().getDiscount("festival");

  3. C

    ShoppingCart sc = new ShoppingCart();
    FestivalDiscount disc = sc.getDiscount("festival");

  4. D

    No line/s of code at CODE SEGMENT can generate the given output because FestivalDiscount is a private inner class.

Show answer

Correct answer

  • B

    Discount disc = new ShoppingCart().getDiscount("festival");

Question 6 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 23 Nov 2025, in the September 2025 term (IIT M DIPLOMA AN EXAM QDD2 23 Nov 2025 NEW). It carries 7 marks.

More questions from this paper

  1. Q1Consider the Java code given below that should print the names of students whose grades are between 70.0 and 90.0 (both…
  2. Q2Consider the code given below.\ interface Vehicle {\ public abstract double getFuelEfficiency();\ }\ class Car implemen…
  3. Q3Consider the Java code given below. Choose the correct option to fill in place of CODE BLOCK so that the output is: Ple…
  4. Q4Consider the following Java code. What will the output be?
  5. Q5Consider the Java code given below. How does class MathUtils look after type erasure?
  6. Q7Consider two Java files located in two different packages as shown below.\ Account.java:\ package com.bank;\ public cla…
  7. Q8Consider the Java code given below.\ interface Shape {\ void draw();\ }\ class ShapeFactory {\ private String type;\ pu…
  8. Q9The merge(K key, V value, remappingFunction) function is defined as: If the specified key is not already associated wit…
  9. Q10Consider the Java code given below that prints the average rating of a set of Rateable objects. From among the options,…
  10. Q11Consider the code given below. Identify the appropriate option(s) to fill in the blank at LINE 1 such that the output o…
  11. Q12Consider the Java code given below.\ class Student {\ private int marks;\ public Student(int marks){\ assert marks >= 0…
  12. Q13Consider the Java code given below. Choose the correct option.
  13. Q14Consider the Java code given below.\ interface Chargeable {\ void showChargeStatus();\ }\ class Laptop implements Charg…
  14. Q15Consider the Java code given below.\ class NegativeBalanceException extends Exception {\ public NegativeBalanceExceptio…