我试图找出这是什么类型的成员变量:
public class Stone {
private Size size; // "Size" refers to a class.
我不知道这个成员变量到底是什么。我以前没有见过成员变量作为类。好像使用了另一个类作为成员变量,这是正确的吗?
最佳答案
它是一个Size
类型的实例变量。这非常好而且非常常见。
来自 Java 教程 Understanding Class Members :
When a number of objects are created from the same class blueprint, they each have their own distinct copies of instance variables. In the case of the Bicycle class, the instance variables are cadence, gear, and speed. Each Bicycle object has its own values for these variables, stored in different memory locations.
关于java - 这是一个什么样的Java成员变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133045/