A final variable can't have its value changed after initialization. : final « Modifiers « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Modifiers » final 
3.6.9.A final variable can't have its value changed after initialization.
public class MainClass {
  public static void main(String[] argv) {
    final int i = 9;
    i = 0;
    System.out.println();
  }
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	The final local variable i cannot be assigned. It must be blank and not using a compound assignment

	at MainClass.main(MainClass.java:4)
3.6.final
3.6.1.final variables
3.6.2.A final class cannot be subclassed.
3.6.3.If a final variable references to an object, the reference must stay the same(not the object)
3.6.4.A final method may not be overridden
3.6.5.final local variable indicates that the value of a variable cannot be changed once assigned a value.
3.6.6.Local variables and method parameters may also be declared as final to enable them to be accessed by local inner classes.
3.6.7.final method may not be overridden.
3.6.8.The final keyword means that the field cannot be changed once initialized.
3.6.9.A final variable can't have its value changed after initialization.
3.6.10.A local variable or method parameter must be declared final if it is to be used by an inner class declared inside a method.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.