创建一个实例变量,它是对象的引用数组

时间:2016-09-23 16:12:28

标签: java

如何创建名为passenger的实例变量,这是对person对象的引用数组。阵列的长度表示车辆可以容纳的乘客数量,即车辆的容量,作为构造函数的参数。

这是我到目前为止所做的事情

public class Vehicle{

  private String LicensePlateNum, make, model;
  private int year, NumOfDoors, NumOfWheels;
  private Person driver;
  private Person [] passengers;
  private int NumOfPassengers;
  private int capacity;



   public Vehicle(String LicensePlateNum, String make, String model, int     year, int NumOfDoors, int NumOfWheels, int capacity){
    this.LicensePlateNum=LicensePlateNum;
    this.make=make;
    this.model=model;
    this.year=year;
    this.NumOfDoors=NumOfDoors;
    this.NumOfWheels=NumOfWheels;
    this.capacity=capacity;
    NumOfPassengers=0;
    driver=null;
    passengers=new Person[capacity];
  }

0 个答案:

没有答案