what is abstract class

  • Thread starter Thread starter P.Sunil
  • Start date Start date
P

P.Sunil

Can any body can give the exact definition of abstract
class and how it can be used.


Regards,
Sunil
 
Hi,

An abstract class is a class that cannot be instantiated. It's main purpose
is to serve as a foundation for inheriting classes by providing, say, a
subset of shared functionality. Abstract classes usually contain one or more
abstract methods - that is, methods that are virtual but have no
implementation as of this class. The inheriting classes must override and
implement such methods to be instantiable.
 
Abstarct classes are classes that cannot be instantiated, and are
frequently either partially implemented, or not at all implemented.
Abstract classes are useful when creating components because they allow
you specify an invariant level of functionality in some methods, but
leave the implementation of other methods until a specific
implementation of that class is needed.

// C#
abstract class WashingMachine
{
public WashingMachine()
{
// Code to initialize the class goes here.
}

abstract public void Wash();
abstract public void Rinse(int loadSize);
abstract public long Spin(int speed);
}



Use of the abstract class is made here

// C#
class MyWashingMachine : WashingMachine
{
public MyWashingMachine()
{
// Initialization code goes here.
}

override public void Wash()
{
// Wash code goes here.
}

override public void Rinse(int loadSize)
{
// Rinse code goes here.
}

override public long Spin(int speed)
{
// Spin code goes here.
}
}
 
Back
Top