3)我的測試程序FinalDemo.Java
package zy.pro.jbd.demo;
/**
* this demo is created to test the usage of the final reserved Word
*/
import zy.pro.jbd.testbase.A;
public class FinalDemo {
final int numInt1 = 16;
final String str = "zy";
final String str1;
final A a = new A();
public FinalDemo() {
str1 = "zy";
}
public static void main(String[] args) {
System.out.println("-------------------------------------------------");
FinalDemo fd = new FinalDemo();
fd.executeFinalTest();
}
public void executeFinalTest() {
this.testFinalInt();
this.testFinalString();
this.testFinalObject();
}
private void testFinalInt() {
//numInt1+=1;
System.out.println(numInt1);
}
private void testFinalString() {
//str=str+"aaaaa";
System.out.println(str);
}
public void testFinalObject() {
a.setT(29);
System.out.println("t: " + a.getT());
/*
* some error will be threw
A b=new A();
a=b;
*/
}
}
本文來自編程入門網:http://www.bianceng.cn/Programming/Java/201107/27859_3.htm