Tt OA 面试真题解析:Retail Inventory、Blue-Green Deployment 基础题

19次阅读
没有评论

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.

第一题考察 Java 面向对象中的多态与方法重写:当父类引用指向子类对象时,调用的是运行时实际对象的 `calculateDiscount()` 实现,因此 `PerishableProduct` 会应用 10% 折扣。第二题考察 Blue-Green 部署在 Kubernetes 中的流量切换与会话路由问题;如果切换后仍有用户访问到旧版本,通常与连接复用、缓存或会话粘滞有关,给出的选项里更贴近“保持同一用户请求落到同一后端”的是 session affinity / sticky sessions。

正文完
 0