FinalAccording to the program context, the Java keyword final has "This is immutable" or "final State" meaning, it can modify the Non-abstract class, Non-abstract class member methods and variables. You may need to stop the change in terms of two understandings: design or efficiency.The final class cannot be inherited, no subclasses, and the method in the
In 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 cannot be inherited. In other words, if a class you never let him inherit, you ca
Final is not used in Java, but it provides us with functions such as defining constants in C, and final allows you to control your members, your methods, or whether a class can be overwritten or inherited. These characteristics make final in Java has an indispensable position, but also learn Java must know and master one of the keywords.
This article explains the final basic usage and the inside advantage and disadvantage, original is not easy, reprint please indicate the sourceThe article is divided into 3 parts, will give you the final keyword on the class, methods and variables of the modification of the role, as well as some of the advantages, for the shortcomings you can refer to the Java Programming Ideas, fourth edition of 156 pages.
Today to talk about the role of the final keyword, although there are a lot of posts about final has been very deep research, but still have to record to talk about their own views deepened under the impression. Go directly to the following topics:First, the role of the final keyword 1. A class that is final modified
What it says is "this part is not modifiable". There are two reasons not to be changed: efficiency, design. There are three things to use in final: data, methods, classes.First, final data
Sometimes the constant invariant of data is very useful, and it can reduce the load of the system when it is running. For these constant invariant data I can be called "constants". "Constants" are mainly used with the fo
1, the final basic usage1.1. Cosmetic classWhen a class is decorated with final, it indicates that the class cannot be inherited. In other words, if a class you never let him be inherited, it can be decorated with final. The member variables in the final class can be final a
Catalogue
Directory
Final meaning
Final variable
Final method
Final class
Final keyword Benefits
Final meaningFinal is a reserved keyword in Java that can declare member variables, methods, and cl
This article focuses on the use of Java final keyword-modified variables.!!!! At the end of the article there are eggs!!!1. Modifier classWhen a class is decorated with final, it indicates that the class cannot be inherited. In other words, if a class you never let him inherit, you can use final to decorate. Member variables in the
defined for this purpose.static variablesStatic variables are similar to static methods. All such instances share this static variable, that is, when the class is loaded, only one storage space is allocated, and all objects of this class can manipulate this block of storage space, although for final it is a matter of course . Look at the following code:classvalue{Static intC=0;Static voidInc () {C++;}}classcount{ Public Static voidprt (String s) {Sys
Final keyword BriefThe final keyword is a very frequent and very high keyword in writing Java programs, and it is necessary to master the use of the final keyword if you want to write Java programs better. Let's take a look at where the final keyword can be decorated
fina
In Java, the final keyword is used to declare an object to have invariance (immutable), where objects include variables, methods, and classes, similar to the const keyword effect in C + +.Immutable means that the state cannot be changed after the object is createdYou can consider using the final keyword from three perspectives:
The code itself: does not want the
Brief introductionSummarize how final and static are used in JavaI. FinalDepending on the context of the program, the Java keyword final has the meaning of "cannot be changed" or "End state", which can be used to modify non-abstract classes, non-abstract class member methods, and variables.The final class cannot be inherited, there are no subclasses, and the meth
First, we can literally understand the Chinese meaning of the final English word: " final, final, decisive; non-changing;". Obviously, if the final keyword is interpreted in Chinese, "immutable" is more appropriate. When you are writing a program, you may encounter situations where I want to define a variable that can
1. Finishing the final of the underlying data memberThis 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.
An introductionSpeaking of final you must know that it is a keyword in Java, so what does it do in Java, you know? If you do not know, please go to this article to understand the next https://www.cnblogs.com/yuanfy008/p/8021673.htmlToday, let's talk about the memory semantics of the final domain in JMM.Re-ordering rules for final fieldsTo get to the point, for
Finalfinal allows you to control your membership, methods, or whether a class can be overwritten or inherited, which makes final a vital part of Java and one of the key words you must know and master when learning java.Final memberWhen you define a variable in a class, precede it with the final keyword, that is, once the variable is initialized, it cannot be changed, and the immutable meaning here is immuta
Access control is annoying, you ' re going to love this artical.
Access modifiers (from less restrictive to more restrictive):
Public , Protected, default (package access), Private
Non-access modifiers (inluding final, abstract and STRICTFP)
1. Class accesses
(1) Default acess
A class with default access has no modifier preceding it in the declaration!
About default access as Package-level access, because a class with default Access can is seen only
//inheritance Disadvantage: Break the encapsulation. /*Final keyword: 1,final is a modifier that can be used to modify classes, methods, and variables. 2,final-Modified classes cannot be inherited. 3,final-Modified methods cannot be overridden. A variable modified by 4,final
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.