函数名和类同名
不需要有返回值、不定义返回值的类型
作用:初始化对象
创建对象都必须要通过构造函数初始化。
一个类中如果没有定义过构造函数,那么该类中会有一个默认的空参数构造函数。
如果在类中定义了指定的构造函数,那么类中的构造函数就没有了。
-------------------------------------------------------
构造函数和一般函数的区别:
构造函数:对象创建时,就会调用与之对应的构造函数,对对象进行初始化。
一般函数:对象创建后需要函数功能时才会调用。
构造函数:对象创建时,会调用一次。
一般函数:对象创建后,可以被多次调用。