JAVA初学者,请问以下程序中特定字符串何时被输出
请问“Hi there”何时被输出,还有负责输出这个字符串的static方法到底算什么?构造方法么?如果不是构造方法为什么可以不写方法名程序代码:
public class B
{
int x;
int y;
static
{
System.out.println("Hi there");
}
public void print()
{
System.out.println("Hello");
}
public static void main(String args[])
{
B st1=new B();
st1.print();
B st2=new B();
st2.print();
}
}
{
int x;
int y;
static
{
System.out.println("Hi there");
}
public void print()
{
System.out.println("Hello");
}
public static void main(String args[])
{
B st1=new B();
st1.print();
B st2=new B();
st2.print();
}
}
[ 本帖最后由 绯苍幻想曲 于 2011-6-28 16:50 编辑 ]
----------------解决方案--------------------------------------------------------
回复 楼主 绯苍幻想曲
我自己来回复下吧。这个static叫静态初始化器,标准形式是static{赋值语句组} ----------------解决方案--------------------------------------------------------