简体   繁体   English

创建 object 和声明 class 变量的新关键字有什么区别?

[英]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 有什么区别?

  1. 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 位置。
  2. 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.

相关问题 在类级别和方法中声明对象之间的区别 - difference between declaring an object on class level and in methods 在Activity中声明最终变量并在onCreate方法上实例化它之间有什么区别? - What is the difference between declaring a final variable in an Activity and instantiating it on the onCreate method? 在定义时和定义后声明局部变量有什么区别? - What is difference between declaring local variable at the time of definition and after definition? Java API中的类“Class”和“class”关键字之间有什么区别? - What is the difference between the class “Class” in the Java API and the “class” keyword? 在接口和类java中声明常量之间有什么区别 - what is the difference between declaring constant in an interface and in class java 声明一个字符串和将其声明为final之间有什么区别? - What is the difference between declaring a String and declaring it as final? 在主类或主方法中声明数组有什么区别? - What's the difference between declaring array in main class or in main method? 声明变量类型之间的区别 - Difference between declaring type of variable 声明对象为其超类与对象之间的区别? - Difference between declaring object as its superclass and its class? 只是声明对象数组和实际创建它的实例有什么区别? - What is the difference between just declaring array of object and actually creating instance of it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM