经典指数          
原因
1169
浏览数
0
收藏数
 

When is the text “Hi there”displayed?
public class StaticTest
{
    static
    {
        System.out.println(“Hi there”);
    }

    public void print()
    {
        System.out.println(“Hello”);
    }

    public static void main(String args[])
    {
        StaticTest st1 = new StaticTest();
        st1.print();
        StaticTest st2 = new StaticTest();
        st2.print();
    }
}

  • Never.
  • Each time a new object of type StaticTest is created.
  • Once when the class is loaded into the Java virtual machine.
  • Only when the main() method is executed.

     举报   纠错  
 
切换
暂时还没有答案,欢迎分享你的解答 . . .
撰写答案
扫描后移动端查看本题