Đang chuẩn bị liên kết để tải về tài liệu:
Java™ How to Program ( Deitel - Deitel) - Phần 6
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Method getcourseName lines 1619 returns a particular GradeBook object s courseName. The method has an empty parameter list so it does not require additional information to perform its task. The method specifies that it returns a stringthis is known as the method s return type. When a method that specifies a return type is called and completes its task the method returns a result to its calling method. For example when you go to an automated teller machine ATM and request your account balance you expect the ATM to give you back a value that represents your balance. Similarly when a statement calls method getcourseName on a GradeBook object the statement expects to receive the GradeBook s course name in this case a string as specified in the method declaration s return type . If you have a method square that returns the square of its argument you would expect the statement int result square 2 Page 94 to return 4 from method square and assign 4 to variable result. If you have a method maximum that returns the largest of three integer arguments you would expect the statement int biggest maximum 27 114 51 to return 114 from method maximum and assign 114 to variable biggest. Note that the statements at lines 12 and 18 each use courseName even though it was not declared in any of the methods. We can use courseName in the methods of class GradeBook because courseName is a field of the class. Also note that the order in which methods are declared in a class does not determine when they are called at execution time. So method getcourseName could be declared before method setcourseName. Method displayMessage lines 2228 does not return any data when it completes its task so its return type is void. The method does not receive parameters so the parameter list is empty. Lines 2627 output a welcome message that includes the value of instance variable courseName. Once again we need to create an object of class GradeBook and call its methods before the welcome message can be .