Java: Advanced Guide to Programming Code with Java (Java, Python, JavaScript, Programming, Code, Project Management, Computer Programming Book 4) by Charlie Masterson
Author: Charlie Masterson [Masterson, Charlie] , Date: August 18, 2020
, Views: 162
One of the most powerful ways to use polymorphic behavior is to use the same method mane, over and over in the same class to get the result you want. So how does polymorphism do this?
Overloaded Methods
Let’s use themakeSound() example. A dog will woof but, if it has an injury, it might whimper instead. How do we use thatmakeSound() method for both sounds? Look at this example:
public class Dog extends Animal {
public void makeSound() {
System.out.println(“Woof!”);
}
public void makeSound(boolean injured) {
}
}
Copyright Disclaimer:
This site does not store any files on its server. We only index and link
to content provided by other sites. Please contact the content providers
to delete copyright contents if any and email us, we'll remove relevant
links or contents immediately.