Java-final the use of a keyword in a property domain
Package com.ray.testobject;/** * Final in attribute domain use * * @author Ray * @since 2015-05-01 * */public class Person {private fin Al String name = "Ray";p ublic String getName () {return name;} private void Set (String name) {//This sentence//this.name=name;//}}
When the domain is identified as final, it is impossible for him to change, that is, there is no set method, only the Get method
The use of the Java-final keyword in the method
Package com.ray.testobject;/** * Final in method use * * @author Ray * @since 2015-05-01 * */public class Test {class person {Public final String GetName () {return ' person ';}} Class Man extends person{//method cannot be overloaded, so error//@Override//public String getName () {////}}}
cannot be overloaded when the method is identified as final
The use of the Java-final keyword inside a class
Package com.ray.testobject;/** * Final in class use * * @author Ray * @since 2015-05-01 * */public class Test {final Class P Erson {private String getName () {return ' person ';}} Because the person class above uses final, it prevents the inheritance//Error here//class man extends person{//}}
When the class is identified as final, it cannot be inherited
Java-final keywords in class, attribute domain, method use