block, I'm going to show a program without the main method, javac it without any errors. public class Test {static { System.out.println ("Static"); Nbsp;system.exit (0);}}
Variables in Java are broadly divided into two broad categories: member variables and local variables.
member variables:
Variables defined within the class body are called member variables;
If the member variable has a
A Brief Introduction to several memory regions of the jvm virtual machine:
Method Area: There is a memory area dedicated to storing loaded class information, constants, static variables, and method code in the java Virtual Machine,
Constant pool: a constant pool is a part of the method area. It is mainly used to store information such as symbolic references in constants and classes.
Heap: used to store clas
Reprinted from:Http://blog.sina.com.cn/s/blog_afddb8ff0101aqs9.htmlStatic code blocks: Some code must be executed at the start of the project , which is executed proactively (when the class is loaded, the static block is executed and executed only once, and static blocks are often used to perform initialization of clas
different object commonalities is defined in the Construction code block.3. Static code block:Format: Execute statement static{static code block in class}Function: initializes the class.When a class enters memory,
Differences between 1.java and C # static member invocationStatic, which is a shared resource, is created when the class is loaded.Java can be invoked through an instance, or by a class name. member name, but it is generally preferable to use the class name. Member this way, because static members belong to the class, not to specific objectsC # can only be called by the class name. Member, and cannot beTo i
The initialization Object Sequence in Java, the usage of Static code blocks, and the usage of Static code blocks
(1) differences between static methods for java static code blocksGenera
Summary: static code blocks are always executed first. A non-static block of code, like a non-static method, is related to an object. Only non-static blocks of code are executed before
Case without parent class1, static code blocks--Static member variables--member variables (instance properties)--code block--constructors2, static code blocks and static member variable
Tag: Name color parses how many sys xtend resultscode example:Case one: When the parent class is not inheritedclassHelloa { PublicHelloa () {System. out. println ("I ' M A class"); } Static{System. out. println ("Static A"); //feature: Executes as the class is loaded and executes only once and takes precedence over the main function. Used to initialize a class. } {System. out. println ("A"); } Public
Class B extends A, then the type a is the parent class with static code blocks, common code blocks, static methods, static member variables, ordinary member variables, common methods.Subclasses are also like this, and then inherit the results about the printout of the progra
PrefaceBase Class AClass B inheritance implements Class A 1 The class is loaded first when you start an instance of new B . (Classes are loaded by the Java class loader only when they are created with the New call) 2 A , then load the subclass B 3 , after loading the parent class A , complete the static action (including static code and variables, their leve
Java constructs static code blocks for common code blocks and static code blocks.
1. Common Code Block
Public static void main (String [] args ){/* Common
See the following program:
1 class A { 2 static{ 3 System.out.println("A static"); 4 } 5 6 { 7 System.out.println("A not static"); 8 } 9 10 public A(){11 System.out.println("A new");12 }13 }14 15 class B extends A{16 static{17 System.out.println("B
Share static and dynamic libraries of C-language code, share static code Dynamics
Shared code can improve efficiency, but for code security and other reasons, c files are rarely retained. Instead, c files are compiled into. o file
non-static in heap memory.* When do I define a static function?* When there is no access inside the function*/
Static Application--tool class:
First create a Class A, then define the main function, then create a tool Class AA, and then run a.
Package A;
public class a{public
static void Main (string[] args)
{
in
Comparison between static code blocks and {} code blocks. Comparison between static code blocks
Example 1:
Public class StaticDemo {System. out. println ("{} code block");} static {Syst
{
System.out.println ("A static");
}
}/*
A StaticStatic BI ' M A classI ' M B class*/
Common code blocks in Java, building code blocks, static code block differences, and code examplesOrder of execution: (priority is from
Common code blocks in Java, building blocks of code, static code block differences, and code examplesThe static code block and the execution of the constructor sequence, has been very c
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.