Polymorphism

Polymorphism is the ability that helps in executing different operations in response to the same message. In OOP, you can implement polymorphism by creating more than one function within a class that have the same name. The difference in the functions lies in the number and the types of parameters passed to each function. This chapter introduces the concept of polymorphism. It explains how to implement function overloading and operator overloading. | Polymorphism Polymorphism is the ability that helps in executing different operations in response to the same message. In OOP you can implement polymorphism by creating more than one function within a class that have the same name. The difference in the functions lies in the number and the types of parameters passed to each function. This chapter introduces the concept of polymorphism. It explains how to implement function overloading and operator overloading. Objectives In this chapter you will learn to fl Describe polymorphism fl Implement function overloading fl Implement operator overloading Chapter 7 Introducing Polymorphism The term polymorphism was derived from the Greek words poly and morphos which mean many and forms respectively. In OOP polymorphism is often expressed by the phrase one interface multiple functions . This expression means that polymorphism allows one interface to be used for multiple functions. You can apply polymorphism for reducing the complexity within the functions of a class of your program. Polymorphism can either be static or dynamic. In static polymorphism the response to a function is decided at compile time. In dynamic polymorphism the response to the function is decided at run time. Static Polymorphism Static polymorphism refers to an entity which exists in various forms simultaneously. The concept of static polymorphism is analogous to the role of a woman who can be a wife a mother a daughter a sister and an executive at the same time. The mechanism of linking a function with an object during compile time is called early binding. It is also known as static binding. C uses two approaches to implement static polymorphism. These are Function Overloading Operator Overloading Function Overloading This approach allows using the same name for two or more functions. Each redefinition of a function must use different types of parameters sequence of parameters or a number of parameters. The type sequence or number of parameters for a .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.