TAILIEUCHUNG - Java™ How to Program ( Deitel - Deitel) - Phần 18

Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 18', 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ả | Salaried Employee . Declaring Interface Payable The declaration of interface Payable begins in Fig. at line 4. Interface Payable contains public abstract method getPaymentAmount line 6 . Note that the method is not explicitly declared public or abstract. Interface methods must be public and abstract so they do not need to be declared as such. Interface Payable has only one methodinterfaces can have any number of methods. We will see later in the book the notion of tagging interfaces these actually have no methods. In fact a tagging interface contains no constant values eitherit simply contains an empty interface declaration. In addition method getPaymentAmount has no parameters but interface methods can have parameters. Page 487 Figure . Payable interface declaration. 1 Fig. 2 Payable interface declaration. 3 4 public interface Payable 5 6 double getPaymentAmount calculate payment no implementation 7 end interface Payable . Creating Class Invoice We now create class Invoice Fig. to represent a simple invoice that contains billing information for only one kind of part. The class declares private instance variables partNumber partDescription quantity and pricePerltem in lines 69 that indicate the part number a description of the part the quantity of the part ordered and the price per item. Class invoice also contains a constructor lines 1219 get and set methods lines 2267 that manipulate the class s instance variables and a tostring method lines 7075 that returns a string representation of an Invoice object. Note that methods setQuantity lines 4649 and setPricePerltem lines 5861 ensure that quantity and pricePeritem obtain only non-negative values. Page 489 Figure . Invoice class that implements Payable. This item is displayed on pages 487 - 488 in the print version 1 Fig. 2 Invoice class implements Payable. 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

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.