📄 comparereference.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -