[英]What is difference between new keyword for create object and declaring class variable?
enter image description here在此处输入图像描述
what is difference between declaring varaible object and object vreated using new keyword?使用 new 关键字声明变量 object 和 object vreated 有什么区别?
public Employee employee;
--> This mean that a reference variable named employee is created but it does not point to anything. --> 这意味着创建了一个名为employee 的引用变量,但它不指向任何东西。 The value of employee variable is null.员工变量的值为 null。 You can not use it directly as it does not have reference to any memory location.您不能直接使用它,因为它没有引用任何 memory 位置。public Employee employee = new Employee();
--> This implies that, a call is given to a constructor function of class will be allocate a reference to the object in memory. --> 这意味着,对 class 的构造函数 function 的调用将分配对 ZE18CFDE6331BD59EB2AC96F8911C4B666Z 中的 ZE1817BF33 中的 object 的引用。 You can use this object to access properties and methods of that class.您可以使用此 object 访问该 class 的属性和方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.