Topic: 关于static

  Print this page

1.关于static Copy to clipboard
Posted by: hahaxiao51
Posted on: 2006-06-09 00:43

在参考书上经常看到static Dog a=new Dog();
请问这里的static是不是只是声明一个dog对象a的引用,而不是声明dog对象为static?
如果是,有什么作用?

2.Re:关于static [Re: hahaxiao51] Copy to clipboard
Posted by: jtaowhy
Posted on: 2006-06-09 08:56

static这里的作用应该是初始化。

3.Re:关于static [Re: hahaxiao51] Copy to clipboard
Posted by: Skybus
Posted on: 2006-06-09 09:22

Listing 1
static MyObject object1 = new MyObject()

In Listing 1, the static keyword is used to indicate that this particular variable, namely object1, is a class variable rather than an instance variable. This means that there will be only one copy of the variable for the class rather than one for each instance of the class. The code segment in Listing 1 not only creates the variable, it also contains a static initializer that gives the object a value. This static initialization occurs automatically when the class containing the variable is first accessed

see http://www.developer.com/java/other/article.php/626421

4.Re:关于static [Re: Skybus] Copy to clipboard
Posted by: hahaxiao51
Posted on: 2006-06-09 15:56

Thanks for your help ,I think Ican understand your means


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923