When you go to the interview, you often encounter such questions: give you two classes of code, they are inherited relationships, each class only the constructor method and some variables, the constructor may have a piece of code on the value of the variable to do some of the operation, there are some of the variable value output to the console of the Code, Then let's judge the result of the output. This is actually a look at our understanding of the initialization order of classes in the case o
Understand static code blocks and construct code blocks from the perspective of virtual machines.
A static code block is a code block modified with the static keyword. A code block is executed only once before the class constructs a code block or constructor. Constructing a code block is simply a code block composed of curly braces. It is characterized by code blocks
(The so-called initialization method Init () is another thing to do after constructing a method, take care not to confuse)In Java, there are two types of initialization blocks: static initialization blocks and non-static initialization blocks. They are all defined in the class, enclosed in curly braces {}, and static code blo
1. Order of Execution1.1. The order of initialization in a class(static variable, static initialization block) = = (variable, initialization block, constructor).1.2, two initialization order with inheritance relationship classesThe parent class (static variable, static initialization block) is the subclass (static variable, static initialization block) and the parent class (variables, initialization blocks, constructors) and subclasses (variables, ini
1. Static initialization block Static initialization blocks are only executed once when the class is first loaded , while static initialization blocks can only assign values to static variables and cannot be assigned to normal member variables.2. (non-static) initialization block (non-static) initialization blocks are executed once each time the instance object
. Access class variables through any instance of the class, and the underlying will turn them into class variables through the class itself, with the same effect
5. Once the value of the class variable is changed, the class variable is accessed through any instance of the class or class, and the resulting value is changed.
6. The class will be initialized before the initialization of the
instance variable (non-static variable)
1. Cannot forward reference, if forward reference, is called illegal
Transferred from: http://www.cnblogs.com/sophine/p/3531282.htmlCommon code blocks in Java, building blocks of code, static code block differences, and code examplesExecution order: (Priority from high to low.) Static code block >mian method > construct code block > Construct method.Where static code blocks are executed only once. The construction code block execu
In Java and Android, what is the difference between the execution order of blocks of code and static code blocks?JavaLet's start with a simple example.Main.java:publicclass Main { staticint1; static { System.out.println(a); } static { 2; } publicstaticvoidmain(String[] args) { System.out.println("Hello World!"); System.out.println(a); }}Output to
1He
Building blocks: Code blocks that are written directly in a classStatic code collapse: blocks of code declared with the static keywordStatic code blocks are constructed before the construction block, and are executed only once when the class is loaded, and later when the class is instantiated, the building
Execution order: (Priority from high to low.) Static code block >mian method > construct code block > Construct method.Where static code blocks are executed only once. The construction code block executes every time the object is created.1 Common code blocks1//Common code block: {} that appears in a method or statement is called a normal code block. Ordinary blocks of code and general execution order of sta
Execution order: (Priority from high to low.) Static code block >mian method > construct code block > Construct method.Where static code blocks are executed only once. The construction code block executes every time the object is created.1 Common code blocks1//Common code block: {} that appears in a method or statement is called a normal code block. Ordinary blocks of code and general execution order of sta
Execution order: (Priority from high to low.) Static code block >mian method > construct code block > Construct method.Where static code blocks are executed only once. The construction code block executes every time the object is created.1 Common code blocksOrdinary code block: {} that appears in a method or statement is called a normal code block. Ordinary blocks of code and general execution order of stat
BBED marks Bad blocks and fixes bad blocks.
Create a test table:
ZBDBA@orcl11g>select * from zbdba;NAME------------------------------------------------------------zbdbahuihuiZBDBA@orcl11g>ZBDBA@orcl11g>ZBDBA@orcl11g>ZBDBA@orcl11g>ZBDBA@orcl11g>select rowid,dbms_rowid.rowid_object(rowid) robject, 2 dbms_rowid.rowid_relative_fno(rowid) fno, 3 dbms_rowid.rowid_block_number(rowid) bno, 4 dbms_rowid.rowid
First, describeStatic code blocks for classes in Java, Construction code blocks, constructor methods, initialization order of static members: First , when the class is loaded, allocate the memory space for the static member variable in the class and give it a default value (the integer type is 0, the float type is 0.0, the Boolean is false, the character type is ' \u0000 ', the reference type is null); Seco
Oracle tablespaces (tableSpace), segments (segment), disk partitions (extent), and blocks are all allocated unit segments used by Oracle to save database objects.
Oracle tablespaces (tableSpace), segments (segment), disk partitions (extent), and blocks are all allocated unit segments used by Oracle to save database objects.
OracleTablespace (TableSpace), Segment (Segment), Disk Area (Extent), Block (Bl
In a recent review of some of the knowledge in Java, here is a way to learn about static blocks of code and construct blocks of code.First of all, the code is balabala some definitions Ah, assignment Ah, the operation of some Java code, surrounded by two curly braces, it becomes a magic block of code{ a=3;} static{ b=4;}Just like the one above.The parentheses add static to the code block, you
Before starting this blog writing, please look at a classic Java face questionpublic class statictest{ public static void Main (String args[]) { Staticfunction (); } static Statictest st = new Statictest (); static{ System.out.println ("1"); } Statictest () { System.out.println ("3"); System.out.println ("a=" +a+ "b=" +b); } public static void Staticfunction () { System.out.println ("4"); } { System.out.println ("2"); }
Java static code blocks, construction code blocks, execution order of construction methodsstatic code takes precedence over non-static code because members that are modified by static are members of a class and are executed as the JVM loads the class, while members that are not statically decorated are also called instance members, and need to create objects to be loaded into heap memory. So static will tak
data, including static members and static blocks of code, to perform initialization operations based on the order in which they are defined "2" static Bowl bowl4 = new Bowl (4); output: Bowl (4) "3" static{ SYSTEM.OUT.PRINTLN ("cupboard class static code block execution"); } Output: Cupboard class static code block executes "4" static Bowl bowl5 = new Bowl (5); output: Bowl (5) After static member initialization, the object is generated throug
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.