TAILIEUCHUNG - murachs Java SE 2010 phần 4

Các kết hợp trang * định dạng đặc biệt làm cho việc học . và tham khảo một cách dễ dàng Một vài năm trước đây, một khách hàng đã sử dụng thuật ngữ "các trang kết hợp" để mô tả phong cách trình bày của chúng tôi, và tên đã bị mắc kẹt. Nó có nghĩa là cuốn sách này trình bày từng chủ đề trong một hai trang. | Chapter 7 How to work with inheritance 233 Access modifiers Keyword Description private Available within the current class. public Available to classes in all packages. protected Available to classes in the same package and to subclasses. no keyword coded Available to classes in the same package. The code for the Product superclass import j public class Product _ private string code private string description private double price protected static int count 0 a protected static variable public Product code description 11 price 0 get and set accessors for the code description and price instance variables public String toStringO override the toString method _ String message Code code n Description description n Price n return message public static Int getCountO create public access for the count variable return count . Description Access modifiers specify the accessibility of the members declared by a class. Public members are accessible to other classes while private members are accessible only to the class in which they re declared. Protected members are accessible within the class in which they re declared. They can also be used by any class that inherits the class in which they re declared. A subclass can access the public and protected members of its superclass but not the private members. Figure 7-5 How to create a superclass Download from Wow eBook 234 Section 2 Object-oriented programming with Java How to create a subclass Figure 7-6 shows how to create a subclass. To indicate that a class is a subclass you follow the class name on the class declaration with the extends keyword and the name of the superclass that the subclass inherits. For example the code for the Book class shown in this figure specifies that the Book class extends the Product class. In other words the Book class is a subclass of the Product class. After you declare the subclass you can extend the functionality of the superclass .

Đã 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.