public class Test {
public static int staticInt;
public static void main(String[] args) {
Test test1 = new Test();
test1.staticInt++;
Test test2 = new Test();
test2.staticInt++;
System.out.println(test1.staticInt);
System.out.println(test2.staticInt);
System.out.println(Test.staticInt);
}
}
2.
public class Test {
static String staticStr;
static {
staticStr = "static 1";
}
public static void main(String[] args) {
System.out.println(staticStr);
}
static {
staticStr = "static 2";
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.