Java Polymorphism | |||
![]() ![]() ![]() | |||
Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous chapter; Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways. For example, think of a superclass called
Remember from the Inheritance chapter that we use the extends keyword to inherit from a class. Now we can create Pig and Dog objects and call the animalSound() method on both of them:
Why And When To Use "Inheritance" and "Polymorphism"?
Tags: Java Java Polymorphism ![]() ![]() | |||
| |||
| |||
|
SIMILAR POSTSJava Inheritance (Subclass and Superclass)Java Inner ClassesJava PackagesJava Classes and ObjectsJava RecursionJava ScopeJava MethodsJava While Loop/Do While Loop/For Loop/For-Each Loop/Break/ContinueJava Switch StatementsJava Short Hand If...Else (Ternary Operator)Java If ... ElseJava MathJava VariablesJava CommentsThe Print() MethodJava SyntaxJava Getting StartedWhat is Java?Machine Learning Types and Programming LanguagesJava Tutorials associated with AP Computer Science ACreating a simple Java Servlet (Web Server Page) with Apache Maven on Microsoft WindowsJava Servlet ExampleDifference between Java and Javascript |