Đang chuẩn bị liên kết để tải về tài liệu:
Lecture An introduction to Object-Oriented Programming with Java - Chapter 13: Inheritance and polymorphism
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
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; define methods, using the protected modifier; parse strings, using a string tokenizer object. | Chapter 13 Inheritance and Polymorphism 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. Define methods, using the protected modifier. Parse strings, using a String Tokenizer object. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance To explain the concept of inheritance, we will consider an example of a class roster. The class roster should contain both undergraduate and graduate students. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance Each student’s record will contain his or her name, three test scores, and the final course grade. The formula for determining the course grade is different for graduate students than for undergraduate students. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance There are two broad ways to design the classes to model undergraduate and graduate students. We can define two unrelated classes, one for undergraduates and one for graduates. We can model the two kinds of students by using classes that are related in an inheritance hierarchy. Two classes are unrelated if they are not connected in an inheritance relationship. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance If two objects are expected to share common behaviors and data, it is better to design their classes using inheritance. Using unrelated classes in such an instance will result in duplicating code common to both classes. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance For this example, we will design | Chapter 13 Inheritance and Polymorphism 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. Define methods, using the protected modifier. Parse strings, using a String Tokenizer object. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance To explain the concept of inheritance, we will consider an example of a class roster. The class roster should contain both undergraduate and graduate students. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 13.1 Defining Classes with Inheritance Each student’s record will contain his or her name, three test scores, and the final course grade. The formula for determining the course grade is different for graduate students than .