package com.keshao.message;public class SystemPath {
/**
* these strings are the paths for this program.
*/
public final static String OUT_PUT_XML = "\\WEB-INF\\output.xml";
public final static String IN_PUT_XML = "\\WEB-INF\\input.xml";
public final static String APPLICATION_CONTEXT_XML = "applicationContext.xml";
public final static String WEB_INF = "\\WEB-INF";
public final static String JDBC_PROPERTY = "\\jdbc.properties";
private static String ROOT = "i am the wrong path";
static {
new SystemPath();
} public static String getRootPath() {
return ROOT;
}
private SystemPath() {
ROOT = "i am the real path";
}
public static void main(String[] args) {
System.out.println(SystemPath.getRootPath());
}
}
/**
* these strings are the paths for this program.
*/
public final static String OUT_PUT_XML = "\\WEB-INF\\output.xml";
public final static String IN_PUT_XML = "\\WEB-INF\\input.xml";
public final static String APPLICATION_CONTEXT_XML = "applicationContext.xml";
public final static String WEB_INF = "\\WEB-INF";
public final static String JDBC_PROPERTY = "\\jdbc.properties";
private static String ROOT = "i am the wrong path";
static {
new SystemPath();
} public static String getRootPath() {
return ROOT;
}
private SystemPath() {
ROOT = "i am the real path";
}
public static void main(String[] args) {
System.out.println(SystemPath.getRootPath());
}
}
static {
new SystemPath();//2
} public static String getRootPath() {
return ROOT;
}
private SystemPath() {
ROOT = "i am the real path";//3
}1 先执行
2 再执行,这是在3重新设置为"i am the real path", 所以是 real path