Java Foundation of Static, Final, this, Super__java

Source: Internet
Author: User

after reading this article, please see the blog from the world of the key line:

Http://blog.csdn.net/chensheng913/archive/2004/07/05/34564.aspx

A. Static

static method:
        We didn't create it with new when we wrote System.in, because it was a static method, which meant telling the Java compiler that I didn't need to create an object of this class to use. In general, static methods often provide utilities for other classes in the application, as well as a large number of static methods in the Java class Library for this purpose.

Static variables:
        Static variables are also called class variables, and all such instances share this static variable, that is, when the class is loaded, only a single storage space is allocated, All objects of this class can manipulate this chunk of storage space (final not discussed). Class variables are superior to other non static variables when the virtual machine is loaded. When inheriting, the static variable of the parent class is loaded first, followed by the subclass.

two. Final
Final member:
        when defining variables in a class, add final. means that once initialized, the immutable meaning is immutable for the base type, and the reference to an object variable cannot be changed. We are also often called constants (constant naming conventions are uppercase).

Final method:
        Declare the method final, which means that you already know that the functionality provided by this method has satisfied your requirements and does not need to be extended. Nor does it allow any class inheriting from this class to override this method, but inheritance can still inherit the method, which means it can be used directly.

Final class:
        When you apply final to a class, the representation class is not inherited by anyone, That means that the design is considered perfect and does not need to be modified or extended.

Three. This and super
This in Java usually refers to the current object, and super is the parent class. When you want to refer to a method or a member of the current object, you can use this to achieve this goal. Another use of this is to call another constructor of the current object. If you refer to something in the parent class, it is super. In the process of inheriting, if the method of the subclass overrides the method of the parent class, you will need to use super if you want to invoke the method that the parent class is overridden. The Special one is that in the constructor, this and super are not "." Connecting a method or member, but using super with the parameter is used to invoke the same form in the parent class constructor (example: Super ()), this is the parameter is called the constructor with the same parameter (example: this ()). In many places, having this makes the program read more smoothly.

Final public class T3 {

/**
* @param args
*/
public static void Main (string[] args) {

Lable: {
int i = 0;
int a = 9;
int b;
b = A + I;
while (true) {
i++;
if (i = = 2) {
Break lable; Tiao DAO Flag
}
}
}//Flag

}

public void GetXXX (String ... strings) {
Lable: {
int i = 0;
int a = 9;
int b;
b = A + I;
while (true) {
i++;
if (i = = 2) {
Break lable; Tiao DAO Flag
}
}
}//Flag
}

public void getxxxx (int A, String ... strings) {

}

public void getxxxx (String ... strings, int a) {//error
//
// }
Static final public void Checkxxxx () {

}
}


Super.www= "KF";
This.www= "Rty";

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.