我得到了这个代码:
//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/