Please login to save your progress.

Visibility and Accessibility Modifiers

Abstract Modifier

The abstract modifier is used in inheritance scenarios. When applied to a class, it forces that class to be inherited, you can't instantiate an abstract class. When applied to a type member, such as a method, it enforces that anything that inherits from the class has to implement the abstract member.

 

In the above example, we've created a class called 'Message'. The Message class cannot be instantiated using the new keyword because it needs to be inherited:

The GetAddress method is also marked as abstract, and you'll notice that we haven't actually provided an implemention, we simply end the declaration with the ; semi-colon line terminator.

When we implement an abstract method in your inherited class, you must specify the override modifier as part of the declaration:

 

Page 12 of 18