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()
 

 

相关文章:

  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-01
  • 2021-06-09
  • 2021-12-27
  • 2021-09-29
  • 2021-09-09
  • 2021-12-28
相关资源
相似解决方案