main ()");
CUPS.CUP1.F (99); (1)
}
//static Cups Cups1 = new Cups ();//(2)
//static Cups CUPS2 = new Cups ();//(2)
}
Output:
Inside Main ()
Cup (1)
Cup (2)
F (99)
Non-static instance initializationThis is nothing to say, is common initialization, in order to execute, can be executed multiple times.
Class Mug {
Mug (int marker) {
print ("
Java also has a similar syntax called instance initialization, which is used to initialize non-static variables for each object. For example:: Initialization/mugs.javaJava "Instance initialization."Class Mug {Mug (int marker) {System.out.println ("Mug (" + marker + ")");}void f (int marker) {System.out.println ("f (" + marker + ")");}}public class Mugs {
Morning:
6:30 was the sound of the construction of the opposite site woke, look at the table, and then sleep;
6:50 wake up again, look at the table, and then sleep;
At 7 o ' clock in the morning, the alarm bell rang and the timekeeping. Don't wake up, sleep for another 5 minutes ...
I'll wake up 7:15. Turn over a side, alas, get up ...
I finally got up 7:20. One side called the Tiger on the opposite bed: "Get up, all 7 O ' 20!" ”
What 7 o ' 20? #@$%* ... "
7:25 Wash finished, rushed into the
("+marker+")");}}class Cups{static Cup cup1;static Cup cup2;static { cup1 = new Cup(1); cup2 = new Cup(2);}Cups(){ print("Cups()");}}public class ExplicitStatic{ public static void main(String[] args){ print("Inside main()"); Cups.cup1.f(99);//(1)} //static Cups cups1 = new Cups();//(2) //static Cups cups2 = new Cups();//(3)}/**output*//*Inside main()Cup(1)Cup(2)f(99)*/Whether the above Code is run (1) or (1) Annotated run (2), the static initialization of Cups will be
involve many actions, especially when it comes to inheritance.
Display static initialization:
//: initialization/Spoon.javapublic class Spoon { static int i; static { i = 47; }} ///:~
The code after static is the same as the static initialization action. This code is only executed once: when an object of this class is generated for the first time, or when the static data member of that class is accessed for the first time.
Non-static instance initialization:
//: initialization/Mugs.java
no static keyword is explicitly used. * Therefore, when the recipient creates an object with a class of dog (the constructor can be regarded as a static method), * or when the dog's static method/static domain is accessed for the first time, the Java interpreter must search for the class path to locate the dog. class file.
3. Explicit static Initialization
Class Cups {static Cup cup1;static Cup cup2;static{cup1 = new Cup(1);cup2 = new Cup(2);}}
4. Non-static instance Initialization
Package CN
()");
}
}
public class Explicitstatic {public
static void Main (string[] args) {
System.out.println ("Inside Main ()"); C26/>cups.c1.f (); (1)
}
static Cups x = new Cups (); (2)
static Cups y = new Cups (); (2)
}///:~
The static initialization module that is used for cups runs when the c1 of a static object is accessed in a row marked (1), or when the row (1) is marked as a comment, and (2) The row is not marked as a comment. if (1) and (2) are marked as annotations, the
main()");Cups.c1.f(99); Cups.c2.f(100);new Cups();}}
Result:
Inside main ()
Cup (1)
Inside static
Cup (2)
F (99)
F (100)
Cup (3)
Cups ();
Explanation:
Static variables are initialized only once.
The data member is initialized before the constructor.
10.3 non-static instance Initialization
class Mug {Mug(int marker) {System.out.println("Mug(" + marker + ")
Existing data is as follows: large bag cup DPK219VAC0011.00 small bag large cup DPK219VBW0011.00 pot of crab meat 1 pound tank RCN061-1VAC0012.00 pot of crab meat 1 pound pot of RCN061-1VBW0012.00 meat 5 mmrfb300-2vb... the existing data is as follows:
Renew bag mug DPK219 VAC001 1.00Renew bag mug DPK219 VBW001 1.00Pot of crab meat 1 lb/tank RCN061-1 VAC001 2.001 pound/pot RCN061-1 VBW001 2.00Strip 5mm RFB
be organized into a special "static phrase" (also known as a "static Block"), as follows. Public class Spoon { staticint i; Static { =n; // /:~Although the code above looks like a method, it is actually just a piece of code that follows the static keyword. Like other static initialization actions, this code executes only once: at the same time, when an object of this class is first generated, or when a static data member belonging to that class is first accessed (even if that class has
objects are created, static data occupies only one storage area. The static keyword cannot be used for local variables, so it can only be used for fields.
8. Non-static instance Initialization
The Code is as follows:
Class Mug{ Mug(int maker){ print("Mug("+maker+")"); } void f(int maker){ print("f("+maker+")");
In the early days of our website operation we need to determine the core keywords and target keywords, the site after we determine the keywords we want to analyze these keywords of the competitor website, here to Baidu search engine optimization For example, the key word to Eagle bathroom as an example:
First we identified our key words for the eagle bathroom, then we have to analyze this keyword Baidu ind
Year-end quality control aimed at the bathroom industryDongpeng Sanitary Ware qideng quality black listDongpeng Sanitary Ware and Dongpeng Sanitary Ware share the same brand and are also engaged in sanitary ware products. Dongpeng Sanitary Ware is different from Dongpeng Sanitary Ware, which is recognized as "authentic goods" in the sanitary ware industry ", the latter is regarded as a "Shanzhai product ". However, just before
(1)
{Produce a food;
P (s_buffnum_a );
P (s_a_ B );
Provide the store with a food;
V (s_num_a );
V (s_ B _a );
}}
Void producer_ B (){
While (1)
{Produce B food;
P (s_buffnum_ B );
P (s_ B _a );
Provide B food to stores;
V (s_num_ B );
V (s_a_ B );
}}
4. There is only one bathroom in a student apartment. The bathroom is very small and can accommodate only one person at a time. Boys and girls living in the
keyword cannot be used for local variables, so it can only be used for domains.Eight. Non-static instance initializationThe code is as follows:Class mug{Mug (intmaker) {Print ("Mug (" +maker+ ")"); } voidFintmaker) {Print ("F (" +maker+ ")"); }} PublicClass mugs{Mug mug1;
Dongpeng Sanitary Ware and Dongpeng Sanitary Ware share the same brand and are also engaged in sanitary ware products. Dongpeng Sanitary Ware is different from Dongpeng Sanitary Ware, which is recognized as "authentic goods" in the sanitary ware industry ", the latter is regarded as a "Shanzhai product ". However, just before the arrival of 2016, "authentic" Dongpeng Sanitary Ware and Shanzhai "Dongpeng Sanitary Ware" have all become the leading chara
Today, I see an article that describes in detail the concept of lock and lock granularity, and why should I lock it as follows? Locking is designed to prevent the confusion of different threads from accessing the same shared resource.A metaphor: People are different threads, toilets are shared resourcesWhen you are in the bathroom, you must lock the door, this is the lock, as long as you are inside, the bathroom
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.