Question 6
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
FestivalDiscount disc = new ShoppingCart().getDiscount("festival");
Discount disc = new ShoppingCart().getDiscount("festival");
ShoppingCart sc = new ShoppingCart();
FestivalDiscount disc = sc.getDiscount("festival");No line/s of code at CODE SEGMENT can generate the given output because FestivalDiscount is a private inner class.