TAILIEUCHUNG - Object Oriented Programming - Lesson 6: Inheritance

Object Oriented Programming - Lesson 6: Inheritance presents Inheritance (Principles, Inheritance hierarchy, Sub class definition, Order of initialization), Reusing through class, To provide new functionality to a subclass. | LESSON VI. Inheritance Trinh Thanh TRUNG (MSc) trungtt@ Content • Inheritance – Principles – Inheritance hierarchy – Sub class definition • extends – Order of initialization • super 1. Principles • Reusing through class: create a new class by extending the functionality of an existing class – The existing class is called the parent class, or super class, or base class – The new class is called the child class, or subclass, or derived class • Relation: New class is a kind of existing class – A subclass inherits the operations, attributes and hierarchical relationships of its super class • If a method is defined in a super class, all of its sub class inherit automatically this method • If a set of member variables are defined in a super class, all of its sub classes inherit the same set of member variables • To provide new functionality to a subclass, we can – Define new methods and variables for this subclass only – Override (execute instead of) methods of the super class in this subclass 4 Example Super class Media Defining basic operations on media products All the behaviors of super class (public attributes, operations, relationships) are inherited by the sub-class Sub class Book Basic operations on media products + Super class Media Specific behaviors on books 5 2. Class hierarchy • The class hierarchy defines the inheritance relationship between classes. – The root of the class hierarchy is the class Object. – Every class in Java directly or indirectly extends (inherits from) this class. • Direct super class: the super class from which a subclass explicitly inherits. – Java: a class can only have one direct super class (single inheritance) • Indirect super class: any class above the direct super class in the class hierarchy • The constructors and destructors are .

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.