Java: Advanced Guide to Programming Code with Java (Java, Python, JavaScript, Programming, Code, Project Management, Computer Programming Book 4) by Charlie Masterson

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]
Language: eng
Format: epub
Published: 2017-02-09

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) {

}

}