tailieunhanh - Lecture Java™ How to Program (8/e) - Chapter 9: Object-oriented programming: Inheritance
After completing this unit, you should be able to: How inheritance promotes software reusability, the notions of superclasses and subclasses, to use keyword extends to create a class that inherits attributes and behaviors from another class, to use access modifier protected to give subclass methods access to superclass members, to access superclass members with super,. | Java™ How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. Inheritance A form of software reuse in which a new class is created by absorbing an existing class’s members and embellishing them with new or modified capabilities. Can save time during program development by basing new classes on existing proven and debugged high-quality software. Increases the likelihood that a system will be implemented and maintained effectively. (C) 2010 Pearson Education, Inc. All rights reserved. When creating a class, rather than declaring completely new members, you can designate that the new class should inherit the members of an existing class. Existing class is the superclass New class is the subclass Each subclass can be a superclass of future subclasses. A subclass can add its own fields and methods. A subclass is more specific than its superclass and | Java™ How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. Inheritance A form of software reuse in which a new class is created by absorbing an existing class’s members and embellishing them with new or modified capabilities. Can save time during program development by basing new classes on existing proven and debugged high-quality software. Increases the likelihood that a system will be implemented and maintained effectively. (C) 2010 Pearson Education, Inc. All rights reserved. When creating a class, rather than declaring completely new members, you can designate that the new class should inherit the members of an existing class. Existing class is the superclass New class is the subclass Each subclass can be a superclass of future subclasses. A subclass can add its own fields and methods. A subclass is more specific than its superclass and represents a more specialized group of objects. The subclass exhibits the behaviors of its superclass and can add behaviors that are specific to the subclass. This is why inheritance is sometimes referred to as specialization. (C) 2010 Pearson Education, Inc. All rights reserved. The direct superclass is the superclass from which the subclass explicitly inherits. An indirect superclass is any class above the direct superclass in the class hierarchy. The Java class hierarchy begins with class Object (in package ) Every class in Java directly or indirectly extends (or “inherits from”) Object. Java supports only single inheritance, in which each class is derived from exactly one direct superclass. (C) 2010 Pearson Education, Inc. All rights reserved. We distinguish between the is-a relationship and the has-a relationship Is-a represents inheritance In an is-a relationship, an object of a subclass can also be treated as an object of its superclass Has-a represents .
đang nạp các trang xem trước