简体   繁体   English

这是哪种Java成员变量?

[英]What kind of Java member variable is this?

I am trying to find out what kind of member variable this is: 我试图找出这是什么类型的成员变量:

public class Stone {

    private Size size; // "Size" refers to a class.

I don't know what exactly this member variable is. 我不知道这个成员变量到底是什么。 I haven't seen a member variable as a class before. 我以前没有将成员变量视为类。 It seems to use another class as a member variable, is this correct? 似乎使用另一个类作为成员变量,这是正确的吗?

It is an instance variable of type Size . 它是Size类型的实例变量。 It's perfectly fine and extremely common. 非常好,非常普遍。

From the Java tutorial Understanding Class Members : 从Java教程了解类成员

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. 对于Bicycle类,实例变量是脚踏圈速,档位和速度。 Each Bicycle object has its own values for these variables, stored in different memory locations. 每个Bicycle对象对于这些变量都有自己的值,存储在不同的存储位置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM