TAILIEUCHUNG - Lesson 9: Polymorphism

This lesson teaches about Polymorphism in C#. | Tutorial Page 1 of 4 Using Excellent Tools to Write Web Applications Tar the .NET Common Language Runtime CLR Home Up Lesson01 Lesson02 Lesson03 Lesson04 Les Lesson06 Lesson07 Lesson08 Lesson09 Lesson10 Les Lesson12 Lesson13 On sale Now C Unleashed is an indepth guide for intermediate to advanced software developers to learn the C programming language and serve as a desktop reference. The C Station Tutorial by Joe Mayo 01 15 01 Lesson 9 Polymorphism This lesson teaches about Polymorphism in C . Our objectives are as follows Learn What Polymorphism Is. Implement a Virtual Method. Override a Virtual Method. Use Polymorphism in a Program. Another primary concept of object-oriented programming is Polymorphism. It allows you to implement derived class methods through a base class pointer during run-time. This is handy when you need to assign a group of objects to an array and then invoke each of their methods. They won t necessarily have to be the same object type. However if they re related by inheritance you can add them to the array as the inherited type. Then if they all share the same method name thai method of each object can be invoked. This lesson will show you how to accomplish this. Listing 9-1. A Base Class With a Virtual Method using System public class DrawingObject public virtual void Draw I m just a generic drawing object. Listing 9-1 shows the DrawingObject class. This will be the base class for other objects to inherit from. It has a single method named Draw . The Draw method has a virtual modifier. The virtual modifier indicate to http Tutorials 6 24 2002 Tutorial Page 2 of 4 derived classes that they can override this method. The Draw method c the Drawingobject class performs a single action of printing the statement I m just a generic drawing object. to the console. Listing 9-2. Derived Classes With Override Methods and using System public class Line .

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.