Java static, this, super, final usage
I. Static
Take a look at the following program:
Public class Hello {Public static void main (string [] ARGs) {// (1)System. Out. println ("Hello, world! "); // (2)}}
I have read this program, and it is no stranger to most of them who have passed Java mathematics. Even if you have never learned Java and other advanced languages, such as C, you should be able to understand the meaning of this Code.
I. Basic usage of the final keywordIn Java, the final keyword can be used to decorate classes, methods, and variables (including member variables and local variables). Here's a look at the basic usage of the final keyword in three ways.1. Modifier classWhen a class is decorated with final, it indicates that the class c
The final keyword represents the immutable. The following is a discussion of the three scenarios used by final keywords: data, methods, and classes.Final data 1, final propertySome "constants" often need to be used in a program. Constants are mainly used in two ways:
Compile-time constants, never change
Initializes a value at run time and does not wa
Final is not commonly used in Java, but it provides functions such as defining constants in C language, final also allows you to control whether your members, methods, or a class can be overwritten or inherited. These features enable final to play an indispensable role in Java, it is also one of the keywords that must be known and mastered when learning Java.
() {static int i=0;//illegal.In fact, understand that static is only a storage place, and use the direct use, do not need to create objects, you can understand the above considerations.In addition, the generic class is not static, only the inner class can be added static to represent the nested class. When final declares properties, methods, and classes in Java, it can be decorated with the keyword final.
Java-based final and static keywords, javafinalstaticI. finalAccording to the context of the program, it can modify non-abstract classes, non-abstract class member methods and variables. The final class cannot be inherited and has no subclass. The methods in the final class are final by default.The
Original works, can be reproduced, but please mark the source address: http://www.cnblogs.com/V1haoge/p/8482909.htmlI. OverviewFinal is one of the most common Java keywords, meaning "final, immutable," in Java.Content that is final modified will be different, they will become the ultimate existence, the content becomes a fixed existence.Second, the role2.1 Final
Take a few minutes to learn about final in Java
.
1, the so-called final refers to the final modified properties, classes, methods can not be changed.
2,final the class, which means that the class cannot be inherited,
For example, if Class B is final decorated,
1. The final class cannot be inherited, so the member methods of the final class have no chance of being overwritten, and the default is final. In the design class, if the class does not need to have subclasses, the implementation details of the class are not allowed to change, and it is certain that the class will no longer be extended, then it is designed as th
The final keyword for Java is often used in daily work, such as when defining constants. If a C + + programmer is born, it may be analogous to the C + + language of the define or the Const keyword, but in fact, they are still in the semantic gap is quite large.In Java, final can be used to decorate classes, methods, and variables (including member variables and local variables). Let's take a brief look at t
Java final summary and javafinal Summary
The Java keyword final has a final and unchangeable meaning. It can modify non-abstract classes, non-abstract class member methods, and variables.
Error: the class "TestFinal" is either abstract or final, not both.
1. The final modif
performed.However, super can also be used to specify the builder call from the line (just like the first operation in the beetle () builder ).The construction of the basic class adopts the same processing process as the pipeline class builder. After the basic shun builder is complete,Instance variables are initialized in the original order. Finally, execute the remaining body parts of the builder.
--------------------------------------------------------------------------------6.8
It programmer development must-all kinds of resources download list, the most complete IT resources in history, personal collection summary. What is the difference between final, finally and finalize.This is a classic interview question, we can almost see it in the interview questions of various companies. Final, finally, and finalize, though they look like the twin brothers, their meanings and usages are q
Final StaticThe final class cannot be inherited, there are no subclasses, and the methods in the final class are final by default. The final method cannot be overridden by a method of a class, but can be inherited. The final mem
final-modifier (keyword) If a class is declared final, it means that it cannot derive a new subclass and cannot be inherited as a parent class. Thus a class cannot be declared as abstract and declared final. Declaring a variable or method final can guarantee that they will not be changed in use. A variable declared as
First, the outset
This blog from: http://www.cnblogs.com/yuananyun/
The final modifier is a relatively simple and commonly used modifier in Java, and a modifier that is more "misunderstood". For many Java programmers, most of them just cursory read a variety of books on the introduction, and then back down, when rememberedJust use it if you have this thing. For when to use the final
First, final keywordsThe advent of inheritance increases the reusability of code and facilitates development. However, there are problems, some classes do not want to be inherited after the description, or some of the methods in the class function is fixed, do not want subclasses to rewrite . But when the subclass inherits these special classes, it can rewrite the method, how to solve it?To solve these problems, you need to use a keyword
1. finishing the final of the underlying data member This is the primary purpose of final, meaning that it is equivalent to the const, C + +, that the member is decorated as a constant, meaning it cannot be modified. As in the Java.lang.Math class, Pi and E are final members, with values of 3.141592653589793 and 2.718281828459045.2.
1. Final variable
Final variable is a constant that cannot be changed once it is initialized.
Class Test1 {
final double PI = 3.14;//The name of the constant is best capitalized public
Test1 () {
PI = 3.14;
}
void Test () {
System.out.println ("PI is:" + pi);
}
public static void Main (string[] args) {
Test1 t = new Test1 ();
T.test (
information in the method to obtain the bytecode of the printname () method, and then execute the commands contained in the printname () method.
2. Summary of the use of final keywords
2. 1 Scope of variables modified by the final keyword
The final keyword is nothing more than a global variable. When a global variable is modified, the scope is a global varia
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.