exam review 2.docx

2 Pages
Unlock Document

Computer programming
Tom Yeung

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 applicat
More Less

Related notes for Comp2129

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.