1. Retail Inventory
A retail inventory management system developed in Java has Product and PerishableProduct classes representing items in the inventory.
class Product {
protected String name;
protected double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {return name;}
public double getPrice() {return price;}
public double calculateDiscount() {return price * 0.05;}
}
class PerishableProduct extends Product {
private String expirationDate;
public PerishableProduct(String name, double price, String expirationDate) {super(name, price);
this.expirationDate = expirationDate;
}
@Override
public double calculateDiscount() {return price * 0.1;}
}
A store manager decides to iterate over each Product object and call its calculateDiscount() method to apply the appropriate discount.
If the inventory includes both Product and PerishableProduct objects, which discount rate will be applied to PerishableProduct objects?
- No discount will be applied.
- 5% discount will be applied.
- 10% discount will be applied.
- The discount rate will be determined at runtime.
2. Blue-Green Deployment
A software organization develops a critical web application that serves millions of users globally. The organization adopts a Blue-Green deployment strategy on their Kubernetes cluster to ensure high availability and zero downtime during updates.
During one of the updates, after the Green environment was live and the traffic was switched, some users reported that they were still running the old version of the application.
What is a solution to prevent this?
- Increase the number of replicas in the Green deployment.
- Force users to clear their browser cache.
- Implement a stronger health check mechanism before routing traffic.
- Utilize session affinity or sticky sessions in the service configuration.
The first question tests Java polymorphism: when a `Product` reference points to a `PerishableProduct` instance, the overridden `calculateDiscount()` method in the child class is invoked at runtime, so the perishable item gets a 10% discount. The second question is about Blue-Green deployment on Kubernetes; if some users still see the old version after traffic switches, the likely mitigation among the options is session affinity or sticky sessions to keep a user's requests consistently routed.