Take a look at Workstation Class together on page 4

xiaoxiao2021-03-06  39

Let's take a look at our custom data type Employee. When it is applied, it doesn't have something different, the same needs to create variables (objects), but the former is defined, and then this is its built-in . There are many properties in this class, there are many ways. At this time, we cannot call its properties directly with the object we have created. Because it is Private Protection Type! I want to modify my name, I want to call the setName () method with the object, and I want to get my name to call GetName () this method. We are completely walking according to the route, this route is "object adjustment method, method change attribute"

Ok, I really believe that you already understand how this is something! Ha ha! Leading up the sails and continue!

Let's take a look at Workstation class now. This is a master class, and the taste of the main () function in C is similar. Among them, in Java, a file only allows for it and must have a primary class, this main class is declared by public! He must have a main () function in C is the same.

Let's take a look at the first statement in this class! Private Employee Jingwei; This statement is to declare an Employee object JINGWEI (no declaration in C ). I want to tell you the difference between "declaration" and "definition". The statement just tells the computer that there is such a variable (object), which does not assign memory for this variable (object) in memory! And only the variable (object) will be assigned memory only when defined. (Required, the init () method is to complete the initialization operation, define the object here, assign a memory. The Start () method is used to initiate the main thread of the browser, the Paint () method to display the Apple interface. These are what the applet program is required. As for the Application program, it is not required. Of course, it doesn't need them in C . About their details, please refer to the relevant books)

Then, it will start an object, and it will have practical significance for the object of Jingwei. Don't have this idea: "Try to operate the class!" Just as I said in front, the principle of TV can't watch TV! This is meaningless! Look at this statement jingwei = new Employee (); it means to define an object of an Employee type. At this point, I want to tell you: "Jingwei this is what you want to have." It has all the properties and methods described in the class. Let me list it one by one:

/ * All Employee objects have these properties. These properties of the corresponding object are stored for each of the newly assigned a single memory. I mean that every object has its own "unique" one * /

Private string name; // employee name

Private int Age; // employee age

Private char sex; // employee gender

Private float emolument; // employee salary

Private boolean lunch; // employee lunch

/ * All EMPLOYEE objects have these methods. But only one in memory * /

Public void heater () {// This method is to process the lunch for processing employees

Lunch = true;

}

Public void setname (String a) {// This method is to modify the name name = A of the employee;

}

Public string getName () {// This method is to get the employee's name

Return Name;

}

/ * However, in fact, when creating this object, the computer allocates memory only all attributes of this object, and does not assign memory to the method. The method only one is that all objects are all objects, so no matter how many objects have been created, the computer will only assign a memory for a method. * /

I think I still give an example, or you are not nicknameless. Ha ha!

See my statement "Private Boolean Lunch;" The company does not care about lunch, each employee needs to take a meal. We think now, the company's space is all memory capacity, your work is part of the memory in the computer (one of each employee is assigned when creating objects). You bring lunch to the company, put on your desk. "Lunch" occupies a corner of your desk (accounting for a memory capacity of your own "object"). This lunch only belongs to yourself, the same others only belong to her! So each employee (object) requires a fast space (memory) to store your own lunch (attribute). This is also the case in the computer. Each time you create an object, you will place a "lunch -lunch" attribute (all properties owned by the object) in memory.

Computers will only assign memory to objects' properties. Because every object is different! Just like lunch taking lunch and giving lunch that I have taught in the company is not the same! But the method is different. The rice belt is cold at noon, you need to use a microwave to heat it. The microwave oven can not bring you, the company has (only a space of the company), it is placed on the lunch table. Do you think, who is the microwave? It belongs to all employees! Because each employee can use it. Not having to bring a part of each employee. It can be seen that each employee (object) has a lunch (attribute), but all employees (objects) are only a microwave (method). All employees (objects) can change their lunch (attributes) in the hot and hot state of this microwave (method). Collection! This is the case in the computer, the method only one, for all objects! And attributes are one per object because each object is different. Don't tell me, you still don't understand, or I will hit the wall, huh, huh :)

转载请注明原文地址:https://www.9cbs.com/read-62413.html

New Post(0)