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 trial

C#

Brandon Cooper
Brandon Cooper
3,249 Points

Abstract class purpose?

I understand the purpose of the abstract keyword is to communicate with other programmers that it is a base class in which sub classes should derive from. However, wouldn't a simple comment next to the class provide the same information without require the BasicInvader.cs file to be created? What other benefits result from the abstract keyword? Thanks!

1 Answer

Steven Parker
Steven Parker
231,122 Points

It's better than a comment because it's enforced by the compiler.

By declaring a class "abstract", you're telling the compiler not to allow this class to be instantiated. It can only be used through inheritance by a subclass. The subclass must implement methods that are declared but not implemented in the abstract base class.