Java programming notes 9 object-oriented 4

Source: Internet
Author: User

Class-related keywords final, static, this, super

1. Final Modifier

1) final class of the modifier class, which cannot be inherited

2) modify the final variable of a variable, that is, a constant. The constant must be assigned an initial value when it is defined. Final int min; the statement is incorrect.

3) Final method of the modifier, which cannot be overwritten by the quilt class.

 

2. Static Modifier

1) class variables and instance variables

Instance variables of different objects are allocated with different memory spaces to share the memory space of the same class of variables.

Class variables can be referenced directly by class names, and instance variables must be referenced by class objects.

2) class method and instance method

The class method allocates memory space when the class is added to the memory. It can be directly referenced by the class name.

The instance method allocates memory space only when an object is generated and must be referenced by an object.

Note: The instance variables in the class are not allowed in the class method. You can only use the class variables in the class (in fact, it is easy to understand that the instance variables have not been generated when the class method is called)

The instance method can use both class variables and instance variables.

 

3, this keyword

This indicates a reference to the class itself (that is, the object itself ).

Http://webservices.ctocio.com.cn/java/213/9194713.shtml

This link is good,

 

4, super keyword

The super keyword indicates a reference to the parent class. If you want to use the member variables and methods of the overwritten parent class in the subclass, use super.

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.