package com.cwcec.test; public class Car { int num; String color; public void Car() { System.out.println("成员函数:Car()"); } public Car() { System.out.println("构造函数:Car()"); } public Car(int num,String color) { this(); //必须处于第一行 this.num=num; this.color=color; } public void run() { System.out.println(num + "," + color); } } public class Demo { public static void main(String[] args) { // TODO Auto-generated method stub Car car = new Car(); car.run(); car.Car(); } }
output:
构造函数:Car()
0,null
成员函数:Car()