Such as:public class innerclassdemo{int x;Class a{static int a = 0;//It is illegal to write this way.static final int b=0;//It's legal to write this}}
Java class load order, the class is loaded first, the static variable is initialized, and then the object is created, and
only static final fields, and each field exports a constant. Classes that use these constants implement this interface to avoid using the class name to decorate the constant name.The constant interface pattern is a bad use of the interface. Specific references are as follows:
The constant interface pattern is a poor use of interfaces. That a class uses
1. IdentifiersIdentifier: Used to represent the class name, variable name, method name, array name, valid character sequence of file nameIdentifiers by any order of letters, underscores such as: Name, User_age, $page identifier characters cannot be numeric identifiers cannot be reserved keywords in Java2. KeywordsHow many Java keywords (keyword) are there?51+2 a reserved word = 53 Keywords (
Such as:public class innerclassdemo{int x;Class a{static int a = 0;//is not legal to write this way.static final int b=0;//It's legal to write this.}}Answer: to put it simply, define a static domain or method that requires a static environment or a top-level environment, where the static environment specifically says that if you add static Class A In your example
publicclassFieldReflactTest{publicstaticfinalStringa="test";protectedintb;privateintc;Stringd;publicstaticvoidmain(String[]args){Field[]fields=FieldReflactTest.class.getDeclaredFields();for(Fieldfield:fields){Stringdescriptor=Modifier.toString(field.getModifiers());//获得其属性的修饰descriptor=descriptor.equals("")==true?"":descriptor+"";System.out.println(descriptor+field.getName()+"="+field.get(newFieldReflactTest()));}}}Java uses reflection to get static
This article mainly introduces the use of PHP class constants, examples of the concept of class constants in PHP, characteristics and related use of skills, the need for friends can refer to the following
The examples in this article describe the usage of PHP class
Java defines Map constants, List constants, and map constants.
Generally, static code blocks are used. For example:
Public final static Map map = new HashMap (); static {map. put ("key1", "value1"); map. put ("key2", "value2 ");}
The following is a simple method for defining Map
Java defines Map constants, List constants, and map constants.
Generally, static code blocks are used. For example:
Public final static Map map = new HashMap (); static {map. put ("key1", "value1"); map. put ("key2", "value2 ");}
The following is a simple method for defining Map
1. Custom Constants
the value of a constant can only be scalar data ( Boolean , integer , float and the string ) or null .
Once a constant is defined, it cannot be redefined or undefined.
There are two ways of defining this:
with define () function to define constants
Define (' STATUS ', 3); Case is not sensitive if the third argument is set to True
Echo STATUS;
with Const keyword to defin
Php customizes global constants and class constants/*** 1. define (name, value, case_insensitive) customizes global constants. the default value is case sensitive. * 2. const defines class constants. * 3. do not use "$" * 4. do no
Php customizes global constants and class constants *** 1. define (name, value, case_insensitive) customizes global constants. the default value is case sensitive. * 2. const defines class constants. * 3. do not use "$" * 4 before
/** * 1, define (name,value,case_insensitive) custom global constants, default case Sensitive * 2, Const defines class constants. * 3, the constant name do not use "$" * 4, the name of the constant all use uppercase letters. *///defines global constants Languagedefine (' LANGUAGE ', ' China '); Echo language;//language
members, using classes to access static members "so that the individual accessors are also easy to distinguish""At the business logic level, it is possible to differentiate whether it is a static method: The method uses a non-static method if it is a certain instance object. If the method applies to all objects, set the method to a static method. 】Although a non-static method is also an object reference to the encoding area for execution, $this in the method can specify the object for operation
for first, and then the attribute is searched layer by level, which is the problem that needs attention."The overriding mechanism created by the inheritance chain is to ensure the priority of access and to ensure the personalization of subclasses""It is also important to note that in the overriding mechanism of inheritance, a property cannot be lower than the parent's original property (that is, if the parent class uses public, the subclass can only
Form: Character constant is an example of a single quote: ' A 'String constants are a number of characters "HelloWorld" caused by double quotation marksMeaning: A character constant is the equivalent of an integer value (asc| | Value), you can join the expression operation, directly take the variable to useA string constant represents an address value (where the character is stored in memory)Memory Size:Character
specifications, so that other programmers to achieve
2, when multiple peer class, all need to implement a function, but the way to achieve different;
Summary:
1, the interface can not be instantiated, all the methods in the interface can not have the main;
2. A class can implement multiple interfaces, separating class demo implements if1,if2,if3{} with commas (
;start ();$p =new Phone ();$p->start ();
When to use the interface:1, set specifications, let other programmers to achieve2, when a number of peer class, all need to implement a function, but the way of implementation is different;Summary:1, the interface can not be instantiated, the interface of all methods can not have the subject;2, a class can implement multiple interfaces, separated by a comma
, but the way of implementation is different;
Summary:
1, the interface can not be instantiated, the interface of all methods can not have the subject;
2, a class can implement multiple interfaces, separated by a comma (,) class demo implements if1,if2,if3{}
3, the interface can have attributes, but must be constants, consta
JAVA Learning (III): Basic Java syntax (conversion of variables, constants, data types, operators and data types), java OperatorsBasic Java syntax (conversion of variables, constants, data types, operators, and data types)
1. Vari
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.