The final keyword in Java is used to restrict the behavior of the user, in other words, to restrict our programmers. Final can be used to modify: variables, methods, classes.1) Java final variableWhen final is used to modify a variable, the value of
Final keyword1. If we want a class to not be inherited by other classes (perhaps because of security considerations), you can use final.ExamplesFinal class a{} class extends a{}; // will error Echo "OK";? >2. If we want a method, such as a
Interface (interface): The interface is equivalent to class. All the methods in the interface are abstract methods. When you declare a method in an interface, you can use the abstract keyword or you can not use it. Typically, the abstract keyword
This article introduces the content of "PHP class and object" Final keyword, has a certain reference value, now share to everyone, the need for friends can refer to
Final keyword
To be declared Final:
1. Class, cannot be inherited. 2. Methods, can
Use the final keyword in the definition of a class to declare classes, properties, methods, and subscripts. final declared classes cannot be inherited, andfinal declared properties, methods, and subscripts cannot be overridden. Let's look at an
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
Final keyword, the university has never understood, accompany to work, depressed ... Or maybe the university really didn't study hard. First of all, final give a look at English words is not the final, what is the final?Xiao Zhang now take everyone
PHP 5 has a new final keyword. If a method in the parent class is declared final, the child class cannot overwrite the method. If a class is declared final, it cannot be inherited.Example #1 Final Method
1.Final KeywordsMeaning: The final and finalfunction :1. If a method in the parent class is declared final, the child class cannot overwrite the method.if a class is declared final, it cannot be inherited.2. Attributes cannot be defined as final,
A. Final value of the variable cannot be changedB. Final methods cannot be rewrittenC. The final class cannot be inherited 1. Final classThe final class cannot be inherited, so the member methods of the final class have no chance of being
Public classMain {{//building blocks (called when constructing an object, prior to construction method execution)System.out.println ("I am a building block!") "); } Static{//static blocks (executed at class load time and executed only once
I. Final in Java can be used in data, methods, classes1.FIANL Decorated data: ConstantsWhen using the final keyword in front of a variable definition, the variable must be initialized at the time of definition, as follows:Private Final Static int
Use Java to do the project, but find a lot of Java Foundation is not very clear. (Learn a little bit about it)Keyword: public protected private default finalPublic: All places are available,Protected: Can be used in the same class, or in the same
Objective
In the usual logical code, we rarely use the final keyword, but in reading some of the source when the final keyword is still very commonly used, the main use of the following several, this article is for personal learning and use, not
1. The role of the final keyword 1.1, Final decorated class: Cannot be inherited by another class; 1.2, final Modified method: cannot be overridden by a quilt class 1.3, final modified variables: In two cases, reference variables, basic type
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 keyword (can be read, not writable, read-only)1. The value of the final variable cannot be changed①, final member variable②, final local variable (formal parameter)//meaning "argument" is not allowed to change once it is passed into my method2.
Java learning Note Object-oriented static,final keyword i. Static keyword1. Overview:Static, statically decorated members belong to a class, do not belong to a single object, are shared by all objects, exist in a static zone, and static members take
The final keyword's role I think we should be very clear, can recite backwards.
1.final properties are immutable
2.final method is not covered
The 3.final class is not inheritable
This blog is to further elaborate the final keyword.
First of all,
Staticstatic means "global" or "static"1. There are two types of class member variables that can be classified according to whether they are static: A variable that is statically modified, called a static variable or a class variable, and a variable
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.