Hi!
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();
}}
When will the string "Hi there" be printed?
A - Never.
B - Each time a new instance is created.
C - Once when the class is first loaded into the
Java virtual machine.
D - Only when the static method is called explicitly.
The answer is C, but what meaning have line 2? I have never seen static
word alone.
thanks in advance.