Summary of private, static, and final identifiers

Source: Internet
Author: User
Summary of private, static, and final identifiers
 
Reprinted from: http://zhidao.baidu.com/question/163628551.html
 
 
 1. static indicates static. It belongs to the class. It can be called directly in its own class, or in other classes by class name. method name. Without static, it indicates an instance method and must be called by an instance. The same is true in this class. instance call is required. private indicates private. // For example, private class demo {//. The demo class is private. // note that the class cannot be modified using private. // when the class is modified to private, it does not mean anything. // because no external object can access the demo class. private string STR; // In this case, the STR attribute is private. // The external class cannot access this attribute. Private void Hello () {// In this case, the external class will not be able to access Hello () method: // For example, you certainly want to have some private things. // you can use ordinary people's ideas to Understand Java OOP} // you can use the private Keyword: this makes your  Program  safer. // variables are usually declared in private. // then, this class controls this attribute through the set get method. 3. final-Modifier (Keyword) If a class is declared as final, it means that it cannot generate a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared both abstract and final. Declare variables or methods as final to ensure that they are not changed during use. Variables declared as final must be declared with an initial value, which can only be read and cannot be modified in future references. Methods declared as final can only be used and cannot be overloaded. 

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.