TAILIEUCHUNG - Object Oriented Programming using Java phần 2

trong lớp ngoại trừ khả năng tạo các đối tượng. Nhưng, đó là một rất nhiều tiềm năng, vì nó có thể được sử dụng để tạo ra bất kỳ số lượng đối tượng! Mỗi đối tượng sẽ có các biến của nó được gọi tên và tuổi. Có thể có nhiều "người chơi" bởi vì chúng tôi có thể làm cho các đối tượng mới để đại diện cho người chơi mới theo yêu cầu. | in the class except the potential to create objects. But it s a lot of potential since it can be used to create any number of objects Each object will have its own variables called name and age. There can be many players because we can make new objects to represent new players on demand. A program might use this class to store information about multiple players in a game. Each player has a name and an age. When a player joins the game a new PlayerData object can be created to represent that player. If a player leaves the game the PlayerData object that represents that player can be destroyed. A system of objects in the program is being used to dynamically model what is happening in the game. You can t do this with static variables An object that belongs to a class is said to be an instance of that class and the variables that the object contains are called instance variables. The methods that the object contains are called instance methods. For example if the PlayerData class is used to create an object then that object is an instance of the PlayerData class and name and age are instance variables in the object. It is important to remember that the class of an object determines the types of the instance variables however the actual data is contained inside the individual objects not the class. Thus each object has its own set of data. The source code for methods are defined in the class yet it s better to think of the instance methods as belonging to the object not to the class. The non-static methods in the class merely specify the instance methods that every object created from the class will contain. For example a draw method in two different objects do the same thing in the sense that they both draw something. But there is a real difference between the two methods the things that they draw can be different. You might say that the method definition in the class specifies what type of behavior the objects will have but the specific behavior can vary from object .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.