public abstract class Test {
private String test1 = getTest1();
public void test() {
System.out.println(test1);
}
protected abstract String getTest1();
}
public class Test2 extends Test {
public void show() {
this.test();
}
public static void main(String... strings) {
Test2 test2 = new Test2();
test2.show();
}
@Override
protected String getTest1() {
// TODO Auto-generated method stub
return "test";
}
}
結果:
test
public enum Test3 {
TEST33("123", "456");
final private String name;
private String value;
private Test3(String name, String value) {
this.name = name;
this.value = value;
}
public static void main(String... strings) {
System.out.println(Test3.TEST33.name);
System.out.println(Test3.TEST33.value);
}
}