Java-final keywords in class, attribute domain, method use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.