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

正文內(nèi)容

外文資料翻譯--一切都是對象-免費閱讀

2025-06-21 04:42 上一頁面

下一頁面
  

【正文】 it returns the number of characters in a string. You can also see the use of the return keyword, which does two things. First, it means “Leave the method, I?m done.” Second, if the method produces a value, that value is placed right after the return statement. In this case, the return value is produced by evaluating the expression ( ) * 2. You can return any type you want, but if you don?t want to return anything at all, you do so by indicating that the method returns void. Here are some examples: boolean flag() { return true。 = false。} // 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 forgets 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()。 and back:char c = ch。 the reason C++ is hybrid is to support backward patibility with the C language. Because C++ is a superset of the C language, it includes many of that language?s undesirable features, which can make some aspects of C++ overly plicated. The Java language assumes that you want to do only objectoriented programming. This means that before you can begin you must shift your mindset into an objectoriented world (unless it?s already there). The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages. In this chapter you?ll see the basic ponents of a Java program and learn that (almost) everything in Java is an object. You manipulate objects with references Each programming language has its own means of manipulating elements in memory. Sometimes the programmer must be constantly aware of what type of manipulation is going on. Are you manipulating the element directly, or are you dealing with some kind of indirect representation (a pointer in C or C++) that must be treated with a special syntax? All this is simplified in Java. You treat everything as an object, using a single consistent syntax. Although you treat everything as an object, the identifier you manipulate is actually a “reference” to an object. You might imagine a television (the object) and a remote control 1(the reference). As long as you?re holding this reference, you have a connection to the television, but when someone says, “Change the channel” or “Lower the volume,” what you?re manipulating is the reference, which in turn modifies the object. If you want to move aroundthe room and still control the television, you take the remote/reference with you, not the television. Also, the remote control can stand on its own, with no television. That is, just because you have a reference doesn?t mean there?s necessarily an object connected to it. So if you want to hold a word or sentence, you create a String reference: But here you?ve created only the reference, not an object. If you decided to send a message to s at this point, you?ll get an error because s isn?t actually attached to anything (there?s no television). A safer practice, then, is always to initialize a reference when you create it:String s = asdf。} void nothing(){return。一旦將 s 傳遞給此方法,就可以把他當作其他對象一樣進行處理(可以給它傳遞消息)。正如你可能料想的那樣,這些信息像 Java 中的其他信息一樣,采用的都是對象形式。如: (arg1,arg2,arg3)。方法的基本組成部分包括:名稱、參數(shù)、返回值和方法體。所以在使用 x前,應先 對其賦一個適當?shù)闹怠?DataOnly 類除了保存數(shù)據(jù)外沒別的用處,因為它沒有任何成員方法。 } 盡管這個類除了存儲數(shù)據(jù)之外什么也不能做,但是仍舊可以像下面這樣創(chuàng)建它的一個對象; DataOnly data = new DataOnly()。 但是,在定義它的所有方法之前,還沒有辦法能讓它去做更多的事情(也就是說,不能向 它發(fā)送任何有意義的消息)。這樣做就消除了這類編程問題(即“內(nèi)存泄漏”), 這是由于程序員忘記釋放內(nèi)存而產(chǎn)生的問題。在 C++中,你不僅必須要確保對象的保留時間與你需要這些對象的時間一樣長,而且還必須在你使用完它們之后,將其銷毀。當用 new 創(chuàng)建一個 Java 對象時,它可以存活于作用域之外。 縮排格式使 Java 代碼更易于閱讀。 作用域 大多數(shù) 過程型語言都有作用域( scope)的概念。一旦 Java 看到 null,就知道這個引用
點擊復制文檔內(nèi)容
畢業(yè)設計相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1