Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMaryam Kamar
2,549 Pointsi understood the concept, but can't we just make everything in the animal class abstract then? e.g. makeSound()
...since each animal makes a different sound anyway so what's the point of not making everything abstract?
Caleb Kemp
12,755 PointsCaleb Kemp
12,755 PointsI can think of two possible reasons why a developer might not want an abstract class
makeSound()
for the animal class.Your code never requires the animals to make sound, making the
makeSound()
method unnessesary.Like how the auto class was separated into motorcycles and cars subclasses, you might also want to separate the animal class into soundAnimals and quietAnimals (for animals that don't make sounds such as Sea Urchins). In that case, you would probably only want soundAnimals to have the
makeSound()
method.In many cases creating a
makeSound()
abstract class for the animal class would be a great idea. I know you were just thinking aloud, but I thought you might want to hear what some possible exceptions might be. Hope it helps