声明,实例化与初始化一个对象有什么区别?
what is the difference between Declaring Objects and Initializing an object?
与该主题相关的三种术语:声明(declaring),初始化(Initializing)和实例化(Instantiation)。
- 声明:表明变量的数据类型与名称,将变量名与对象类型相关联。
- 实例化:new关键字是创建对象的Java运算符。
- 初始化:new运算符之后是对构造函数的调用,该构造函数将初始化新对象。将值放入分配的内存中。 这是使用new关键字时类的构造方法的作用。
- Declaration: The code set in bold are all variable declarations that associate a variable name with an object type.
- Instantiation: The new keyword is a Java operator that creates the object.
- Initialization: The new operator is followed by a call to a constructor, which initializes the new object.