comparereference.java

来自「主要是对于JAVA的编程的基本语言 希望能够帮得上你。」· Java 代码 · 共 33 行

JAVA
33
字号
package Operator;

import java.awt.Button;

/*
 A reference variable is a name that is used in Java to reference
 an instance of a class. Reference variables can be tested to see
 if they point to the same object by using the == operator. 
 
 */
class CompareReference {
   public static void main(String [] args) {
      Button a = new Button("Exit");
      Button b = new Button("Exit");
      Button c = a;
      System.out.println("Is reference a == b? " + (a == b));
      System.out.println("Is reference a == c? " + (a == c));
   }
}

/*
 This code creates three reference variables. The first two, a and b, 
 are separate Buttons which happen to have the same label. 
 The third reference variable, c, is initialized to point to the same 
 instance that a refers to. When this program runs, the following 
 output is produced: 
 
 Is reference a == b? false
 Is reference a == c? true 
 
 As we can see by this result, both a and c reference the same instance 
 of a Button. 
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?