Usage of this,static keywords in Java

Source: Internet
Author: User

1, the use of this keyword:
A, member variable and local variable name, call member variable in the method body, need to use
The This keyword.
b, you can use this when passing the class's own instantiated object as a parameter.
C, inner class, calling methods or variables of an external class,
Available: class name. this. (variable or method name)
D, in the same class, you can use the This keyword to invoke an overloaded construction method of the same name, if you call other construction methods in the constructor method,
Must be placed in the first row of the current construction method).
2, the method of parameter delivery:
A, the value of the base data type is passed
b, pointer passing with reference data type

3. Static keyword
A, the static method is a method without this, in the static method body, cannot call the non-static method, also cannot call the nonstatic member variable
Conversely, you can call the static method in the non-static method body. static method,
Called only by means of the class name. Of course, if you use an instantiated object to call the static method, it is also
Yes, it's just not recommended.
b, static variables are also called static variables, the difference between static and non-static variables is: Static variables are all
object, not the current object owned by the static variable, is initialized when the object is created, exists
Multiple replicas, and the static variable does not have more than one copy.
C, static code block, if there is more than one static code block in a class, then the load execution order is executed sequentially
4. jar Package and Library: encapsulation of a range of functions (packaged)
5.super keywords
A, in the parent class existing logic to add some of their own methods, you can use super. Need to be placed first in the current construction method.
B, when a subclass has a member variable of the same name as the parent class, or a member method of the same name, the element in the child class is greater than the precedence of the element in the parent class, so a method or member variable in the parent class needs to be called with the Super keyword
C, through super after directly followed by parameters, you can call the parent class construction method

Usage of this,static keywords in Java

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.