Static Field/Method, Initialization Block Cont. (After compile)
package com.foo;
import java.io.PrintStream;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
public class BaseObject {
│
│ private static long second = 0L;
│ private String name;
│
│ public BaseObject() {
│ name = "";
│ System.out.println("I am class block initialization.");
│ second++;
│ System.out.println("I am constructor.");
│ }
│
│ public BaseObject(String name) {
│ [[http://this.name/][this.name]] = "";
│ System.out.println("I am class block initialization.");
[[http://this.name/][ this.name]] = name;
│ second++;
│ }
│
│ public String getName() { return name; }
│
│ public void setName(String name) {
│ [[http://this.name/][this.name]] = name;
│ }
│
│ public static long getSecond() { return second; }
│
│ public static void setSecond(long second) { second = second; }
│
│ public String toString() { return ReflectionToStringBuilder.toString(this); }
│
│ public static void main(String args[]) {
│ System.out.println(getSecond());
│ BaseObject bo1 = new BaseObject("First One");
│ BaseObject bo2 = new BaseObject("Seconde One");
│ BaseObject bo3 = new BaseObject("Third One");
│ System.out.println((new StringBuilder())
│ │ .append(bo1)
│ │ .append("__")
│ │ .append(getSecond())
│ │ .toString());
│ System.out.println((new StringBuilder())
│ │ .append(bo2)
│ │ .append("__")
│ │ .append(getSecond())
│ │ .toString());
│ System.out.println((new StringBuilder())
│ │ .append(bo3)
│ │ .append("__")
│ │ .append(getSecond())
│ │ .toString());
│ }
│
│ static { System.out.println("I am static block initialization."); }
}