class value {
int v;
public value(int v) {
this.v = v;
}
}
public class finaltest {
final int f1 = 1;
final int f2;
public finaltest() {
f2 = 2;
}
public static void main(string[] args) {
final int value1 = 1;
// value1 = 4;
final double value2;
value2 = 2.0;
final value value3 = new value(1);
value3.v = 4;
}
}
public class finaltest {
/* ... */
public void finalfunc(final int i, final value value) {
// i = 5; 不能改变i的值
// v = new value(); 不能改变v的值
value.v = 5; // 可以改变引用对象的值
}
}
class personalloan{
public final string getname(){
return "personal loan";
}
}
class cheappersonalloan extends personalloan{
@override
public final string getname(){
return "cheap personal loan"; //compilation error: overridden method is final
}
}
public class test {
public static void main(string[] args) {
string a = "hello2";
final string b = "hello";
string d = "hello";
string c = b + 2;
string e = d + 2;
system.out.println((a == c));
system.out.println((a == e));
}
}
public class test {
public static void main(string[] args) {
string a = "hello2";
final string b = gethello();
string c = b + 2;
system.out.println((a == c));
}
public static string gethello() {
return "hello";
}
}
public class test {
public static void main(string[] args) {
final myclass myclass = new myclass();
system.out.println(++myclass.i);
}
}
class myclass {
public int i = 0;
}
public class test {
public static void main(string[] args) {
myclass myclass1 = new myclass();
myclass myclass2 = new myclass();
system.out.println(myclass1.i);
system.out.println(myclass1.j);
system.out.println(myclass2.i);
system.out.println(myclass2.j);
}
}
class myclass {
public final double i = math.random();
public static double j = math.random();
}