Mastering Microsoft Visual Basic 2008 phần 5

đường dẫn là đường dẫn đầy đủ của các tập tin với hình ảnh. Bộ sưu tập hình ảnh của điều khiển ImageList là một bộ sưu tập của các đối tượng hình ảnh, chứ không phải các tập tin trong đó các hình ảnh được lưu trữ. Điều này có nghĩa rằng các tập tin hình ảnh không cần phải | WHO CAN INHERIT WHAT 425 structure of Method4. It has no code and the End Function statement is missing. Method4 is declared with the MustOverride keyword so you can t instantiate an object of the Parentclass type. A class that contains even a single member marked as MustOverride must also be declared as MustInherit. Place a button on the class s test form and in its code window attempt to declare a variable of the Parentclass type. VB will issue a warning that you can t create a new instance of a class declared with the MustInherit keyword. Because of the MustInherit keyword you must create a derived class. Enter the lines from Listing in the Parentclass module after the end of the existing class. LISTING Derived Class Public Class DerivedClass Inherits ParentClass Overrides Function Method4 As String Return I m the derived Method4 End Function Public Function newMethod As String This is the derived Class s newMethod calling Method2 of the parent Class End Function End Class The Inherits keyword determines the parent class. This class overrides the Method4 member and adds a new method to the derived class newMethod. If you switch to the test form s code window you can now declare a variable of the DerivedClass type Dim obj As DerivedClass This class exposes all the members of Parentclass except for the Method2 method which is declared with the Protected modifier. Notice that the newMethod function calls this method through the MyBase keyword and makes its functionality available to the application. Normally we don t expose Protected methods and properties through the derived class. Let s remove the MustInherit keyword from the declaration of the Parentclass class. Because it s no longer mandatory that the Parentclass be inherited the MustInherit keyword is no longer a valid modifier for the class members. So Method4 must be either removed or implemented. Let s delete the declaration of the Method4 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
7    91    2    28-06-2024
48    96    1    28-06-2024
Đã 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.