Inheritance and Polymorphism in Programming

Inheritance is one of the core concepts of object-oriented programming. It allows classes to receive, or inherit, all the behaviors and attributes of other classes (Farrell, 2016). Classes that inherit from others can still have behaviors and attributes unique to them (Farrell, 2016). Therefore, inheritance is a useful technique when creating objects that are sufficiently similar to share some behaviors, but not sufficiently similar to allow them to be defined by one class. This allows code to be reused throughout the program and helps save time and avoid errors that can occur when creating similar code for similar classes. Examples of such use can be in a graphical application: geometric shapes can be defined by an array of points and share a method that draws them on the screen. Each subclass (rectangle, triangle, polygon) would need a unique method to determine its area.

Polymorphism is another key concept of object-oriented programming; it allows the program to interact with objects as instances of multiple classes. This allows one to interact with similar objects in different ways depending on the context and specific requirements of the interaction. For instance, an application that works with employee records can implement subclasses for different specific positions with unique behaviors. However, certain behaviors can be shared, for instance, sending an email or altering one’s schedule is independent of one’s position. Furthermore, under polymorphism, a subclass can override the methods of its superclass, providing unique behaviors. Going back to the graphical application example, a Polygon superclass can provide a GetArea() method suitable for most shapes. However, specific shapes can override it if a more efficient formula exists to determine their area. In such a situation, polymorphism provides additional means of reusing existing code, saving time and preventing errors, supplementing inheritance.

Reference

Farrell, J. (2016). Java Programming (8th ed.). Boston, MA: Cengage Learning.

Cite this paper

Select style

Reference

StudyCorgi. (2022, January 11). Inheritance and Polymorphism in Programming. https://studycorgi.com/inheritance-and-polymorphism-in-programming/

Work Cited

"Inheritance and Polymorphism in Programming." StudyCorgi, 11 Jan. 2022, studycorgi.com/inheritance-and-polymorphism-in-programming/.

* Hyperlink the URL after pasting it to your document

References

StudyCorgi. (2022) 'Inheritance and Polymorphism in Programming'. 11 January.

1. StudyCorgi. "Inheritance and Polymorphism in Programming." January 11, 2022. https://studycorgi.com/inheritance-and-polymorphism-in-programming/.


Bibliography


StudyCorgi. "Inheritance and Polymorphism in Programming." January 11, 2022. https://studycorgi.com/inheritance-and-polymorphism-in-programming/.

References

StudyCorgi. 2022. "Inheritance and Polymorphism in Programming." January 11, 2022. https://studycorgi.com/inheritance-and-polymorphism-in-programming/.

This paper, “Inheritance and Polymorphism in Programming”, was written and voluntary submitted to our free essay database by a straight-A student. Please ensure you properly reference the paper if you're using it to write your assignment.

Before publication, the StudyCorgi editorial team proofread and checked the paper to make sure it meets the highest standards in terms of grammar, punctuation, style, fact accuracy, copyright issues, and inclusive language. Last updated: .

If you are the author of this paper and no longer wish to have it published on StudyCorgi, request the removal. Please use the “Donate your paper” form to submit an essay.