TAILIEUCHUNG - Lecture An introduction to object-oriented programming with Java: Chapter 13 - C. Thomas Wu

Chapter 13 - Inheritance and polymorphism. After you have read and studied this chapter, you should be able to: Write programs that are easily extensible and modifiable by applying polymorphism in program design; define reusable classes based on inheritance and abstract classes and abstract methods; differentiate the abstract classes and Java interfaces; define methods, using the protected modifier; parse strings, using a String Tokenizer object. | ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 13 - Chapter 13 Inheritance and Polymorphism Animated Version Introduction to OOP with Java 4th Ed, C. Thomas Wu © The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 13 - Chapter 13 Objectives After you have read and studied this chapter, you should be able to Write programs that are easily extensible and modifiable by applying polymorphism in program design. Define reusable classes based on inheritance and abstract classes and abstract methods. Differentiate the abstract classes and Java interfaces. Define methods, using the protected modifier. Parse strings, using a String Tokenizer object. Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 13 - Simple Example We can effectively model similar, but different types of objects using inheritance Suppose we want to model dogs and cats. They are different types of pets. We can define the Pet class and the Dog and Cat classes as the subclasses of the Pet class. Pet Dog Cat Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 13 - The Pet Class class Pet { private String name; public String getName() { return name; } public void setName(String petName) { name = petName; } public String speak( ) { return “I’m your cuddly little pet.”; } } Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 13 - Subclasses of The Pet Class class Cat extends Pet { public String speak( ) { return “Don’t give me orders.\n” + “I speak only when I want to.”; } } class Dog extends Pet { public String fetch( ) { return “Yes, master. .

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.