O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.6. Declaring an Abstract Base Class

Query represents the base class abstraction from which all the actual query types manipulated within our application are inherited. The user should never create an actual instance of a Query object. Rather, a Query object in our program always addresses one of the inherited query types. To enforce this usage model, we modify the Query class definition with the abstract keyword:

abstract public class Query { ... }

The abstract keyword tells both the compiler and readers of our program that it is illegal to create an actual Query class instance. For example, the following attempt to create a Query object triggers a compile-time error:

// error: Query is abstract
Query q = new Query();

Rather, a Query object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required