求问java的一个构造函数怎么写!!!急!!!

package l07b;/** * A program to test the Car data-type class. * * @author Mark Young (A00000000) */public class LotsaCars { public static void main(String[] args) { Car car1, car2, car3, carToForget, car54; // create first three Cars car1 = new Car(); car2 = new Car(); car3 = new Car(); // Create cars 4 thru 53 for (int i = 4; i <= 53; i++) { carToForget = new Car(); } // Create Car 54 car54 = new Car(); // Report on Cars System.out.println("\n\n" + "Lots of Cars\n" + "------------\n\n" + "Car #1's VIN is " + car1.VIN + "\n" + "Car #2's VIN is " + car2.VIN + "\n" + "Car #3's VIN is " + car3.VIN + "\n" + "Car #54's VIN is " + car54.VIN + "\n"); }}----------------------------------------------------------------------------------以上,要写一个构造函数,输出

你需要的构造函数:

public class Car {
public static int NUM = 0;
public int VIN = 0;
public Car(){
NUM++;
VIN = NUM;
}
}
思考点:在于new几次之后,car里面的vin属性就是几。所以需要用到一个静态变量来存储,创建对象的次数,然后在将这个变量赋值给vin。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网