Study Guides (390,000)
CA (150,000)
UofM (800)
COMP (20)

COMP 2150 Study Guide - Final Guide: Virtual Function, Microsoft Visual Studio, Code Segment

Computer Science
Course Code
COMP 2150
John Anderson
Study Guide

This preview shows half of the first page. to view the full 2 pages of the document.
Now any and every class that derives from the Person class must provide the implementation
details for the GetExerciseHabits( ) method. That is what adding the
abstract keyword does. It is like signing a contract. If you derive from an abstract base
class, you sign a contract that details how to implement its abstract methods.
If the abstract class includes more than one abstract method, derived classes must
provide implementation details for every abstract method included in the base class.
Abstract classes can include regular data field members, regular methods, and virtual
methods in addition to abstract methods. Remember that a virtual method tags the
method as being capable of being overridden in a derived class.This does not mean that
all derived classes have to provide new implementation details for those tagged as virtual,
just that they can. Other than the fact that the derived class must implement all abstract
methods, no additional special keywords are used when a new class is defined to inherit
from the abstract base class.
All .NET languages only support inheritance, which means that a class can
extend or derive from at most one class. One-way languages such as C# and Java work
around this is by implementing multiple interfaces
You learned that the abstract keyword enables you to create a class solely for the purpose
of inheritance. Abstract classes cannot be instantiated. Objects can only be created
using classes derived from the abstract class.The purpose of an abstract class is
to provide a common definition of a base class so that multiple derived classes can share that
definition. Sealed classes provide a completely opposite type of restriction.They restrict the
inheritance feature of object-oriented programming.When you add the modifier sealed
to a class, the class cannot be a base class. In order to define a sealed class, add the keyword
sealed following the access modifier
Sealed classes are defined to prevent derivation.
Objects can be instantiated from the class, but subclasses
cannot be derived from it.
You may also add the keyword sealed to class members of nonsealed classes.This is especially
helpful when the method has been defined as virtual in a base class, indicating that it
can be overridden in subclasses. If you do not want subclasses to be able to provide new
implementation details, add the keyword sealed. Doing so keeps derived classes from being
able to override the method.
You should not seal a method unless that method is itself an override of another method in
some base class. If it is a new method and you do not want subclasses to override it, do not
declare it as virtual in the first place. If however, you have overridden a base class method, the
sealed keyword provides a way of ensuring that the override supplied to a method is a
“final” override. No subclasses can override it again.
One of the added features of C# is partial classes.When you created a Windows application,
you may recall that the heading automatically generated by Visual Studio read partial
class Form1.The definition for the class is split into two files.These two source code files
You're Reading a Preview

Unlock to view full version