当前位置: 技术问答>java相关
一个非常简单的问题?
来源: 互联网 发布时间:2015-11-12
本文导语: calss Test { statci int ob=-1; public test() { ob++; System.out.println("total objects="+ob); } } class Subtest txtends Test {} the class is instantiated with the following line of code: Subtest t=new Subtest(); which of the following statements are true t...
calss Test
{
statci int ob=-1;
public test()
{
ob++;
System.out.println("total objects="+ob);
}
}
class Subtest txtends Test
{}
the class is instantiated with the following line of code:
Subtest t=new Subtest();
which of the following statements are true the first time we try to instantiate
Subtest? Assume no other instances of these two classes have been instantiated;
答案是 total objects =0
Assume no other instances of these two classes have been instantiated是什么意思?能解释一下吗?
{
statci int ob=-1;
public test()
{
ob++;
System.out.println("total objects="+ob);
}
}
class Subtest txtends Test
{}
the class is instantiated with the following line of code:
Subtest t=new Subtest();
which of the following statements are true the first time we try to instantiate
Subtest? Assume no other instances of these two classes have been instantiated;
答案是 total objects =0
Assume no other instances of these two classes have been instantiated是什么意思?能解释一下吗?
|
呵呵,首先你给的程序有太多的语法错误。
那句话意思很简单:你实例化一次Test或Subtest静态变量objects的值就会增加,出题者只是说最初一次实例化Subtest时objects的值是多少(那句话就是说说以前没有对Test或Subtest进行过任何实例化)。
出题者本来是为了避免出现理解错误,这里却又带来了新的理解疑惑;)
那句话意思很简单:你实例化一次Test或Subtest静态变量objects的值就会增加,出题者只是说最初一次实例化Subtest时objects的值是多少(那句话就是说说以前没有对Test或Subtest进行过任何实例化)。
出题者本来是为了避免出现理解错误,这里却又带来了新的理解疑惑;)
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。