java - 我如何知道对象中存在哪些变量?

标签 java eclipse variables inheritance extends

我得到了这个代码:

//Class X is created, and then class Y is derived from class X:
class X
  {
  protected int m;
  }


class Y extends X
{
  private int n;
  public Y (int m, int n)
    {
     this.m = m;
     this.n = n;
    }
  public String toString ()
    {
     return m + ", " + n;
    }
}

//Class Y is used in the following way:
class UseY
{
  public static void main (String[] args)
  {
    Y y = new Y (3, 4);
    System.out.println (y);
  }
}

因此如您所见,代码涉及继承。

有人问我:

执行程序 UseY 时会创建哪个输出?对象 y 中存在哪些变量?

我的回答:

输出是: 3,4。 对象y中的变量是m和n。

但我不确定我的第二个答案。 变量到底是什么意思?我的回答正确吗?

最佳答案

我会说:

The object y has a nested member, called n and a derived member from its super-class, called m.

关于java - 我如何知道对象中存在哪些变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27906019/

相关文章:

java - PrintWriter 是否缓冲?

java - 如何从eclipse windows执行java程序到Linux服务器

java - Eclipse Checkstyle 插件可以与 Java 1.5 一起使用吗?

eclipse - 在Mapreduce中做job chaining时,如何解决chainmapper is not applicable for the arguments错误?

eclipse - eclipse插件打开后如何执行操作

javascript - 第 n 个 child 的变量

java - ClassNotFoundException : No RObject is found to match class type of org. redisson.RedissonMap 编解码器类型为 org.redisson.codec.JsonJacksonCodec

java - memcache 无法在多个节点上运行

python - 如何将变量连接到 Entry 小部件?

Java - 为什么将 "null"分配给变量不会使其可用于 GC? (在此代码段中)