What is polymorphism?

This is a recommends products dialog
Top Suggestions
Starting at
View All >
Language
French
English
ไทย
German
繁體中文
Country
Hi
All
Sign In / Create Account
language Selector,${0} is Selected
Register & Shop at Lenovo Pro
Register at Education Store
Pro Tier Benefits
• Save up to an extra 20% on Think everyday pricing.
• Spend $15K, advance for FREE to Plus Tier with increased benefits.
Plus Tier Benefits
• Save up to an extra 25% on Think everyday pricing.
• Spend $50K, advance for FREE to Elite Tier with increased benefits.
Elite Tier Benefits
• Save up to an extra 30% on Think everyday pricing.
Reseller Benefits
• Access to Lenovo's full product portfolio
• Configure and Purchase at prices better than Lenovo.com
View All Details >
more to reach
PRO Plus
PRO Elite
Congratulations, you have reached Elite Status!
Pro for Business
Delete icon Remove icon Add icon Reload icon
TEMPORARILY UNAVAILABLE
DISCONTINUED
Temporary Unavailable
Cooming Soon!
. Additional units will be charged at the non-eCoupon price. Purchase additional now
We're sorry, the maximum quantity you are able to buy at this amazing eCoupon price is
Sign in or Create an Account to Save Your Cart!
Sign in or Create an Account to Join Rewards
View Cart
Your cart is empty! Don’t miss out on the latest products and savings — find your next favorite laptop, PC, or accessory today.
Remove
item(s) in cart
Some items in your cart are no longer available. Please visit cart for more details.
has been deleted
Please review your cart as items have changed.
of
Contains Add-ons
Subtotal
Proceed to Checkout
Yes
No
Popular Searches
What are you looking for today ?
Trending
Recent Searches
Hamburger Menu
{"backgroundColor":"#e6f4fa","sideMsg":"","data":[{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Page2c25a670-a473-4e84-837b-ae1510087748","language":{"en_au":"%3Cp%3E%3Cstrong%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fp2-ofp.static.pub%2FShareResource%2Fanz%2Fimg%2FMasthead_Carousel%2Flfs-logo--reversed.svg%22%20alt%3D%22logo%22%20width%3D%2290%22%20height%3D%2218%22%20style%3D%22text-wrap-style%3A%20initial%3B%22%2F%3E%3C%2Fstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3B%7C%26nbsp%3BEXTRA%205%25%20off%20selected%20products%20%2B%202X%20rewards%20points.%20%5E%3Ca%20href%3D%22%2Fshopping-faqs%2Fgem-visa%2F%3FipromoID%3Dau_hello_bar_latitude%22%20target%3D%22_blank%22%20textvalue%3D%22T%26amp%3BCs%22%20style%3D%22text-wrap-style%3A%20initial%3B%20color%3A%20rgb(41%2C%2078%2C%20149)%3B%20text-decoration%3A%20underline%3B%22%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%20color%3A%20rgb(41%2C%2078%2C%20149)%3B%22%3ET%26amp%3BCs%3C%2Fspan%3E%3C%2Fa%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%20color%3A%20rgb(41%2C%2078%2C%20149)%3B%22%3E%26nbsp%3B%3C%2Fspan%3Eapply.%26nbsp%3B%3Ca%20href%3D%22%2Fcontact%2Fsales-support%2F%22%20target%3D%22_blank%22%20textvalue%3D%22Chat%20Now%20to%20Order%22%20style%3D%22text-wrap-style%3A%20initial%3B%20color%3A%20rgb(41%2C%2078%2C%20149)%3B%20text-decoration%3A%20underline%3B%22%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%20color%3A%20rgb(41%2C%2078%2C%20149)%3B%22%3EChat%20Now%20to%20Order%3C%2Fspan%3E%3C%2Fa%3E%3C%2Fspan%3E%3C%2Fp%3E","en":""},"id":"Page2c25a670-a473-4e84-837b-ae1510087748"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Page807d43be-aaf2-4c29-8fc3-b6d20867fb0a","language":{"en_au":"%3Cp%3E%3Cimg%20src%3D%22https%3A%2F%2Fp3-ofp.static.pub%2FShareResource%2Fanz%2Fimg%2FAU-amazonmusic-unlimited-horizontal-130x26-0827.png%22%20alt%3D%22Amazon%20Music%20Unlimited%22%20width%3D%22130%22%20style%3D%22text-wrap%3A%20wrap%3B%22%2F%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3BGet%204%20months%20Free.%20%2412.99%2Fmonth%20after.%20New%20subscribers%20only.%20Terms%20apply.%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22https%3A%2F%2Fwww.lenovo.com%2Fau%2Fen%2Fp%2Faccessories-and-software%2Fsoftware-subscription%2Famazon-subscription%2Frr00125299%3FipromoID%3Dau_pc_carousel_banner_amu%22%20target%3D%22_blank%22%20style%3D%22text-wrap%3A%20wrap%3B%20color%3A%20rgb(79%2C%20129%2C%20189)%3B%22%3ELEARN%20MORE%3C%2Fa%3E%3C%2Fp%3E","en":""},"id":"Page807d43be-aaf2-4c29-8fc3-b6d20867fb0a"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Pagedb993c61-6637-48fd-8b8e-b7bf1f150b16","language":{"en_au":"%3Cp%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3B%3C%2Fspan%3E%3Cimg%20src%3D%22https%3A%2F%2Fp3-ofp.static.pub%2Ffes%2Fcms%2F2022%2F09%2F20%2Fsgy8gw8u4tymopd8g2224x0drocvbb133978.png%22%20alt%3D%22zip-logo%22%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%2F%3E%3Cspan%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%3E%7C%26nbsp%3BEXTRA%205%25%20off%20selected%20products%20%2B%202X%20rewards%20points.%20%5E%3C%2Fspan%3E%3Ca%20href%3D%22%2Fprogram%2Fzipmoney%2F%3FipromoID%3Dau_hello_bar_zip%22%20target%3D%22_blank%22%20textvalue%3D%22T%26amp%3BCs%22%20style%3D%22text-wrap-style%3A%20initial%3B%20color%3A%20rgb(79%2C%20129%2C%20189)%3B%20text-decoration%3A%20underline%3B%22%3E%3Cspan%20style%3D%22text-wrap-style%3A%20initial%3B%20color%3A%20rgb(79%2C%20129%2C%20189)%3B%22%3ET%26amp%3BCs%3C%2Fspan%3E%3C%2Fa%3E%3Cspan%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%3E%26nbsp%3Bapply.%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Fcontact%2Fsales-support%2F%22%20target%3D%22_blank%22%20textvalue%3D%22Chat%20Now%20to%20Order%22%20style%3D%22text-wrap-style%3A%20initial%3B%20color%3A%20rgb(79%2C%20129%2C%20189)%3B%20text-decoration%3A%20underline%3B%22%3E%3Cspan%20style%3D%22text-wrap-style%3A%20initial%3B%20color%3A%20rgb(79%2C%20129%2C%20189)%3B%22%3EChat%20Now%20to%20Order%3C%2Fspan%3E%3C%2Fa%3E%3C%2Fp%3E","en":""},"id":"Pagedb993c61-6637-48fd-8b8e-b7bf1f150b16"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Page0e9b3fce-f050-479b-af47-a1fd9fd40650","language":{"en_au":"%3Cp%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%3E%3Cbr%2F%3E%3C%2Fp%3E%3Cp%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%3E%3Cstrong%3EBetter%20Together%3C%2Fstrong%3E%20%7C%20%3Cspan%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%3EGet%2020%25%20off%20selected%20monitors%20%26amp%3B%2035%25%20off%20selected%20Lenovo%20accessories%20with%20your%20new%20PC%20for%20a%20limited%20time.%3C%2Fspan%3E%3C%2Fp%3E%3Cp%20style%3D%22text-wrap-mode%3A%20wrap%3B%22%3E%3Ca%20href%3D%22%2Fd%2Fdeals%2Fblack-friday-sale%2F%3FipromoID%3Dau_pc_carousel_banner_accessories%22%20target%3D%22_self%22%20textvalue%3D%22Shop%20PCs%22%20style%3D%22color%3A%20rgb(84%2C%20141%2C%20212)%3B%20text-decoration%3A%20underline%3B%22%3E%3Cspan%20style%3D%22color%3A%20rgb(84%2C%20141%2C%20212)%3B%22%3EShop%20PCs%3C%2Fspan%3E%3C%2Fa%3E%3C%2Fp%3E%3Cp%3E%3Cbr%2F%3E%3C%2Fp%3E","en":""},"id":"Page0e9b3fce-f050-479b-af47-a1fd9fd40650"},"gInfo":""}],"autoRun":true,"displayTerminal":"pc,tablet,mobile"}


What is polymorphism?

Polymorphism is a concept in object-oriented programming that allows objects of different types to be treated as objects of a common superclass. It enables code reusability and flexibility by allowing multiple classes to implement the same method in different ways. This concept is essential for achieving abstraction and encapsulation in programming languages.

How does polymorphism work?

Polymorphism works by creating a relationship between classes using inheritance. When a superclass defines a method, its subclasses can override that method to provide their own implementation. At runtime, the appropriate method is called based on the actual type of the object. This dynamic binding allows for more flexible and extensible code.

What is an example of polymorphism?

Sure, let's say we have a superclass called Animal with a method makeSound(). We can have subclasses like Dog, Cat, and Bird that inherit from Animal and override the makeSound() method with their own unique implementation. When you call the makeSound() method on an object of type Animal, it will invoke the specific implementation based on the actual type of the object.

What are the benefits of using polymorphism?

Using polymorphism in programming brings several benefits. It promotes code reuse and modularity, as classes can share common behaviors through inheritance. It enhances flexibility, allowing new subclasses to be added without modifying existing code. Polymorphism also enables the creation of generic algorithms that can operate on objects of different types.

How is polymorphism different from inheritance?

Inheritance is a mechanism where one class inherits properties and methods from another class. It establishes an "is-a" relationship between classes. On the other hand, polymorphism is a concept that allows objects of different classes to be treated as objects of a common superclass. Polymorphism establishes an "as-a" relationship, enabling objects to exhibit different behaviors while sharing a common interface.

How does polymorphism contribute to code maintenance?

Polymorphism promotes code maintenance by reducing code duplication. With polymorphism, you can define a method once in a superclass and have all its subclasses inherit and override it as needed. This avoids the need to duplicate code across multiple classes, making the codebase easier to maintain. Additionally, when new subclasses are added, the existing code won't require modifications, ensuring backward compatibility.

Can polymorphism be achieved in programming languages other than Java?

Yes, polymorphism is not exclusive to Java. Many object-oriented programming languages, such as C++, Python, and C#, support polymorphism. Although the syntax and implementation details may differ, the underlying concept remains the same. Polymorphism is a fundamental aspect of object-oriented programming and can be leveraged in various programming languages.

Is polymorphism only applicable to object-oriented programming (OOP)?

Polymorphism is primarily associated with OOP paradigms, but the concept can be applied to other programming paradigms too. In functional programming, for example, polymorphism can be achieved through higher-order functions or parametric polymorphism. Although the implementation may vary, the core idea of allowing objects of different types to be treated uniformly can still be realized.

How does polymorphism relate to method overriding?

Polymorphism and method overriding go hand in hand. Method overriding is the process of providing a different implementation of a method in a subclass that is already defined in its superclass. This is achieved by using the same method signature in the subclass as the one in the superclass. Polymorphism allows us to invoke the overridden method based on the actual type of the object, ensuring the correct implementation is executed.

Can polymorphism occur with static methods?

No, polymorphism does not apply to static methods. Static methods belong to the class itself and not to individual objects. They are resolved at compile-time based on the class type rather than at runtime based on the object type. Therefore, static methods cannot be overridden or exhibit polymorphic behavior. When you call a static method, it is always the version defined in the class in which it is declared that gets executed.

What is compile-time polymorphism?

Compile-time polymorphism, also known as method overloading, is a form of polymorphism where multiple methods with the same name but different parameters are defined within a class. The appropriate method to be invoked is determined by the compiler based on the number, types, and order of the arguments passed during method invocation. This allows for different behaviors based on the input provided, enabling code flexibility and readability.

How is polymorphism useful in software development?

Polymorphism plays a crucial role in software development by promoting code reusability, modularity, and extensibility. It allows developers to write generic code that can operate on various types of objects, reducing redundancy and improving efficiency. Polymorphism enables the creation of flexible and adaptable systems, making it easier to maintain and enhance the software over time.

Does polymorphism have any impact on performance?

Polymorphism may have a slight impact on performance compared to direct method calls. This is because polymorphic method invocations involve an extra level of indirection and dynamic binding, which can introduce some overhead. However, modern compilers and runtime systems have optimizations in place to minimize this impact, making it negligible in most cases. The benefits of code flexibility and maintainability often outweigh any minor performance concerns.

What is the relationship between polymorphism and abstraction?

Polymorphism and abstraction are closely related concepts in object-oriented programming. Abstraction refers to the process of representing complex real-world entities as simplified models in code. Polymorphism allows objects to be treated at a higher level of abstraction, where they are seen as instances of a common superclass or interface. This separation between the specific implementation and the general behavior enables code to be written in a more modular and flexible manner.

Can polymorphism be achieved without inheritance?

While polymorphism is commonly associated with inheritance, it is not solely dependent on it. Polymorphism can also be achieved through interfaces or abstract classes, where multiple unrelated classes implement a common interface or extend the same abstract class. This allows objects of different types to be treated uniformly, providing the benefits of polymorphism without relying on class hierarchy.

How does polymorphism contribute to code readability?

Polymorphism enhances code readability by promoting code reuse and eliminating redundancy. With polymorphism, you can write generic code that operates on objects of different types without needing to know their specific implementations. This leads to shorter, more concise code that is easier to understand and maintain. Polymorphism also improves the readability of code by allowing for better organization and encapsulation of related behaviors.

{"pageComponentDataId":"e857fdeft7e51-4b61-84dc-bccec6e68e00","pageComponentId":"e857fdeft7e51-4b61-84dc-bccec6e68e00","isAssociatedRelease":"true","pageComponentDataLangCode":"en_au","configData":{"jumpType":"currentTab","headlineColor":"black","displayNumber":"","styleMode":"vertical","miniCardHoMode":"2","headline":"","products":[{"number":{"t_id":"21kccto1wwau5","language":{"en_nz":"21kccto1wwau5","en_au":"21kccto1wwau5","en":""},"id":"Pageb33ce4b8-4839-4ba3-b993-7296d68a91b8"}},{"number":{"t_id":"21mccto1wwau3","language":{"en_nz":"21mccto1wwau3","en_au":"21mccto1wwau3","en":""},"id":"Page1fa61927-074c-4fe0-a8df-5c94362fb75c"}},{"number":{"t_id":"21lkcto1wwau3","language":{"en_nz":"21lkcto1wwau3","en_au":"21lkcto1wwau3","en":""},"id":"Pageca014688-410e-439a-a4c6-bba2ef6d4715"}},{"number":{"t_id":"21g2cto1wwau3","language":{"en_nz":"21g2cto1wwau3","en_au":"21g2cto1wwau3","en":""},"id":"Page79cd32c8-d467-4d68-b955-d273bb24eda7"}}]},"urlPrefix":"AAAAAAAH","title":"glossary-right-blue-boxes-fragment","pageId":"65b55929-de05-417a-a92a-ccb888d329b0","urlEdit":0,"uri":"/FragmentDirectory/glossary/glossary-right-blue-boxes-fragment.frag","pageComponentUuid":"e857fdeft7e51-4b61-84dc-bccec6e68e00"}
coming coming
Starting at
List Price
Web Price
Web Price:
List Price
Web Price
List Price is Lenovo’s estimate of product value based on the industry data, including the prices at which first and third-party retailers and etailers have offered or valued the same or comparable products. Third-party reseller data may not be based on actual sales.
Web Price is Lenovo’s estimate of product value based on industry data, including the prices at which Lenovo and/or third-party retailers and e-tailers have offered or valued the same or comparable products. Third-party data may not be based on actual sales.
Learn More
See More
See Less
View {0} Model
View {0} Models
Part Number:
Features
See More
See Less
compare
Added!
Great choice!
You may compare up to 4 products per product category (laptops, desktops, etc). Please de-select one to add another.
View Your Comparisons
Add To Cart
Add To Cart
We're sorry,
Products are temporarily unavailable.
Continue shopping
Learn More
Coming Soon
Featured Product
Top Deals of the Day
Oops! No results found. Visit the categories above to find your product.
Save
open in new tab
© 2024 Lenovo. All rights reserved.
© {year} Lenovo. All rights reserved.
Compare  ()
x