freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

網(wǎng)上書店管理系統(tǒng)外文資料翻譯-管理系統(tǒng)(已改無錯(cuò)字)

2023-03-03 02:53:58 本頁(yè)面
  

【正文】 timize these operations). When you create an array of objects, you are really creating an array of references, and each of those references is automatically initialized to a special value with its own keyword: null. When Java sees null, it recognizes that the reference in question isn?t pointing to an object. You must assign an object to each reference before you use it, and if you try to use a reference that?s still null, the problem will be reported at run time. Thus, typical array errors are prevented in Java. You can also create an array of primitives. Again, the piler guarantees initialization because it zeroes the memory for that will be covered in detail in later chapters. You never need todestroy an object In most programming languages, the concept of the lifetime of a variable occupies a significant portion of the programming effort. How long does the variable last? If you are supposed to destroy it, when should you? Confusion over variable lifetimes can lead to a lot of bugs, and this section shows how Java greatly simplifies the issue by doing all the cleanup work for you. Scoping Most procedural languages have the concept of scope. This determines both the visibility and lifetime of the names defined within that scope. In C, C++, and Java, scope is determined by the placement of curly braces {}. So for example: { int x = 12。// Only x available{ int q = 96。// Both x amp。 q available }// Only x available// q is out of scope } A variable defined within a scope is available only to the end of that text after a ?//? to the end of a line is a makes Java code easier to read. Since Java is a freeform language, the extra spaces, tabs, and carriage returns do not affect the resulting cannot do the following, even though it is legal in C and C++:{ int x = 12。 {int x = 96。 // Illegal}}The piler will announce that the variable x has already been defined. Thus the C and C++ ability to “hide” a variable in a larger scop e is not allowed, because the Java designers thought that it led to confusing programs. Scope of objects Java objects do not have the same lifetimes as primitives. When you create a Java object using new, it hangs around past the end of the scope. Thus if you use:{String s = new String(a string)。} // End of scopethe reference s vanishes at the end of the scope. However, the String object that s was pointing to is still occupying memory. In this bit of code, there is no way to access the object after the end of the scope, because the only reference to it is out of scope. In later chapters you?ll see how the reference to the object can be passed around and duplicated during the course of a program. It turns out that because objects created with new stay around for as long as you want them, a whole slew of C++ programming problems simply vanish in Java. In C++ you must not only make sure that the objects stay around for as long as you need them, you must also destroy the objects when you?re done with brings up an interesting question. If Java leaves the objects lying around, what keeps them from filling up memory and halting your program? This is exactly the kind of problem that would occur in C++. This is where a bit of magic happens. Java has a garbage collector, which looks at all the objects that were created with new and figures out which ones are not being referenced anymore. Then it releases the memory for those objects, so the memory can be used for new objects. This means that you never need to worry about reclaiming memory yourself. You simply create objects, and when you no longer need them, they will go away by themselves. This eliminates a certain class of programming problem: the socalled “memory leak,” in which a programmer fets to release memory. Creating new data types: class If everything is an object, what determines how a particular class of object looks and behaves? Put another way, what establishes the type of an object? You might expect there to be a keyword called “type,” and that certainly would have made sense. Historically, however, most object oriented languages have used the keyword class to mean “I?m about to tell you what a new type of object looks like.” The class keyword (which is so mon that it will not usually be boldfaced throughout this book) is followed by the name of the new type. For example: class ATypeName { /* Class body goes here */ } This introduces a new type, although the class body consists only of a ment (the stars and slashes and what is inside, which will be discussed later in this chapter), so there is not too much that you can do with it. However, you can create an object of this type using new:ATypeName a = new ATypeName()。 Fields and methods When you define a class (and all you do in Java is define classes, make objects of those classes, and send messages to those objects), you can put two types of elements in your class: fields (sometimes called data members), and methods (sometimes called member functions). A field is an object of any type that you can talk to via its reference, or a primitive type. If it is a reference to an object, you must initialize that reference to connect it to an actual object (using new, as seen earlier). Each object keeps its own storage for its fields。 ordinary fields are not shared among objects. Here is an example of a class with some fields: class DataOnly {int i。double d。boolean b。} This class doesn?t do anything except hold data. But you can create an object like this: DataOnly data = new DataOnly()。 You can assign values to the fields, but you must first know how to refer to a member of an object. This is acplished by stating the name of the object reference, followed by a period (dot), followed by the name of the member inside the object: object Reference. Member or example: data. i = 47。 = 。 = false。 It is also possib
點(diǎn)擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計(jì)相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖片鄂ICP備17016276號(hào)-1