private String createOrderSummary(String orderPersonName, int quantity, int price) {
    String orderPersonName = "Kaptain Kunal";
    String createOrderSummary = "Name: " + orderPersonName;
    createOrderSummary = createOrderSummary + "\nQuantity: " + quantity;
    createOrderSummary = createOrderSummary + "\nTotal: " + price;
    createOrderSummary = createOrderSummary + "\nThank you!";
    return createOrderSummary;
}


它说“ orderPersonName”已经定义。我见过2次以上,但我不明白,因为不是第一个“定义”和第二个“利用”?

你能解释一下吗?

谢谢 :)

最佳答案

它已经在函数的头部定义了;您不能再次创建相同的变量;只需更换

String orderPersonName = "Kaptain Kunal";




orderPersonName = "Kaptain Kunal";

10-07 14:46