You can create a new version
of a member in a derived class for a member (property or method) that
already exists in the parent class. After doing this, when you call that
member in your program, you need to make sure that the right member gets
called, the member in the base class or the equivalent member in the derived
class.

We have just mentioned that you can create a new
version of a member in a derived class for a member (property or
method) that already exists in the parent class. After doing this,
when you call that member in your program, you need to make sure
that the right member gets called, the member in the base class or
the equivalent member in the derived class.

When you create a base class, if you anticipate
that a certain member (property or method) would need to be
redefined in the derived class, you can indicate this to the
compiler. On the other hand, while creating your classes, if you
find out that you are customizing a property or a method that
already exists in the base class, you should let the compiler know
that you are providing a new version. In both cases, the common
member should be created as virtual.

To create a virtual member, in the base class,
type the virtual keyword to the left of the property or
method. Based on this, the Area property of our Circle class can be
created as follows:

When you derive a class from an abstract class, since
the methods (if any) of the abstract class were not implemented, you must
implement each one of them in the derived class. When customizing virtual
members in a derived class, to indicate that a member is already virtual in
the base class and that you are defining a new version, type the override
keyword to the left of its declaration. For example, the Area property in
our Sphere class can be created as follows:

========================================
Square Characteristics
Description: A quadrilateral is a geometric figure that has four
sides and four angles. A square is a quadrilateral that has four equal
sides and four right angles
========================================
Rectangle Characteristics
Description: A quadrilateral is a geometric figure that has four
sides and four angles.
A rectangle is a quadrilateral that has adjacent perpendicular sides.
This implies that its four angles are right.
========================================

Press Enter to close the DOS window and return to your programming
environment

Creating an Abstract
Class

In a program, you can create a class whose role is only
meant to provide fundamental characteristics for other classes. This type of
class cannot be used to declare a variable. Such a class is referred to as
abstract. Therefore, an abstract class can be created only to serve as a
parent class for other classes.

To create an abstract class, type the abstract
keyword to the left of its name. Here is an example:

To create an abstract class, access the Descriptor.cs file and
change it as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Geometry3
{
public abstract class Descriptor
{
public virtual string Describe()
{
return "A quadrilateral is a geometric figure " +
"that has four sides and four angles.";
}
}
}

Abstract Properties and
Methods

When creating a class that would mainly be used as a
base class for future inheritance, you can create one or more properties and
make them abstract. To do this, when creating the property, type the
abstract keyword to its left. Because you would not define the property,
you can simply type the get keyword and its semi-colon in
the body of the property.

A method of a class also can be made abstract. An
abstract method can be a member of only an abstract class. If you make a
method abstract in a class, you must not implement the method. To create an
abstract method, when creating its class, type the abstract keyword
to the left of the method's name. End the declaration with a semi-colon and
no body for the method since you cannot implement it. Here is an example:

========================================
Square Characteristics
Name: Square
Description: A quadrilateral is a geometric figure that has four
sides and four angles. A square is a quadrilateral that has four equal
sides and four right angles
========================================
Rectangle Characteristics
Name: Rectangle
Description: A quadrilateral is a geometric figure that has four sides
and four angles.
A rectangle is a quadrilateral that has adjacent perpendicular sides.
This implies that its four angles are right.
========================================

Press Enter to close the DOS window and return to your programming
environment

Details on Abstract and
Virtual Members of a Class

We saw that, if you create a method marked as abstract
in the body of a class, the method must not have a body. Here is an example: