Created
April 26, 2017 19:04
-
-
Save matanlurey/a295ca34517e60184955b6d836deac90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal { | |
void consume(Food food) { | |
System.out.println("Ate " + food.weight + " pounds of food!"); | |
} | |
void consume(Water water) { | |
System.out.println("Drank " + water.amount + " liters of water!"); | |
} | |
static void main(String[] args) { | |
var animal = new Animal(); | |
animal.consume(new Food(100)); // Prints "Ate 100 pounds of food!" | |
animal.consume(new Water(50)); // Prints "Drank 50 liters of water!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment