Object Oriented Programming using Java phần 3

Nếu một người chơi rời khỏi trò chơi, đối tượng PlayerData đại diện cầu thủ có thể bị phá hủy. Một hệ thống của các đối tượng trong chương trình đang được sử dụng để tự động mô hình những gì đang xảy ra trong trò chơi. Bạn không có thể làm điều này với "tĩnh" biến! | Even an expert programmer won t be familiar with the entire API or even a majority of it. In this book you ll only encounter several dozen classes and those will be sufficient for writing a wide variety of programs. Using Classes from Packages Let s say that you want to use the class in a program that you are writing. Like any class is a type which means that you can use it declare variables and parameters and to specify the return type of a method. One way to do this is to use the full name of the class as the name of the type. For example suppose that you want to declare a variable named rectColor of type . You could say rectColor This is just an ordinary variable declaration of the form type-name variablename . Of course using the full name of every class can get tiresome so Java makes it possible to avoid using the full names of a class by importing the class. If you put import at the beginning of a JAVA source code file then in the rest of the file you can abbreviate the full name to just the simple name of the class Color. Note that the import line comes at the start of a file and is not inside any class. Although it is sometimes referred to as as a statement it is more properly called an import directive since it is not a statement in the usual sense. Using this import directive would allow you to say Color rectColor to declare the variable. Note that the only effect of the import directive is to allow you to use simple class names instead of full names you aren t really importing anything substantial. If you leave out the import directive you can still access the class - you just have to use its full name. There is a shortcut for importing all the classes from a given package. You can import all the classes from by saying import . The is a wildcard that matches every class in the package. However it does not match sub-packages you cannot .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.