集册 Java实例教程 参考值传递的示例

参考值传递的示例

欢马劈雪     最近更新时间:2020-01-02 10:19:05

489
参考值传递的示例

class Product {

  public String model = "Unknown";

  public int year = 2000;
  /*
  时 代 J a v a 公 众 号 提供
  */

  public double price = 0.0;

}

public class Main {

  public static void main(String[] args) {

    // Create a Car object and assign its reference to myCar

    Product myCar = new Product();


    // Change model, year and price of Car object using myCar

    myCar.model = "Civic";

    myCar.year = 2000;

    myCar.price = 9600.0;


    System.out.println("#1: model = " + myCar.model + ", year = " + myCar.year

        + ", price = " + myCar.price);

        /* 
         来自 
        *NowJava.com - 时  代  Java*/

    Main.test(myCar);


    System.out.println("#4: model = " + myCar.model + ", year = " + myCar.year

        + ", price = " + myCar.price);

  }

  public static void test(Product xyCar) {

    System.out.println("#2: model = " + xyCar.model + ", year = " + xyCar.year

        + ", price = " + xyCar.price);

    
展开阅读全文