Tips
1. An abstract class can have abstract as well as
non-abstract methods.
Ex.
abstract class Watch
{
//Non-Abstract
Method
public void Alarm()
{
Console.WriteLine("Alarm
Method: This method provides Alarm features");
}
//Abstract
Method
public abstract void Model();
}
2. An abstract class cannot be sealed or static.
Ex.
sealed abstract class Watch
{
}
3. Abstract class access modifiers cannot be
private, protected, or protected internal.
Ex.
private abstract class Watch
{
}
4. Abstract class declared with abstract keyword.
Ex.
abstract class Watch
{
}
5. Abstract method cannot use in non-abstract
class.
Ex.
class Watch
{
public abstract void Model();
}
6. We cannot change access modifiers when
overriding abstract method in derived class.
Ex.
//Abstract Method
public abstract void Model();
//Abstract Method Implementation in derived
class
private override void Model()
{
Console.WriteLine("Derived
Model");
}
7. Virtual or abstract member’s access modifiers
cannot be private.
Ex.
private abstract void Model();
8. An abstract method cannot be marked virtual.
Ex.
public virtual abstract void Model();
9. A Derived class cannot inherit more than one
abstract class.
10. An abstract member cannot be static.
11. We cannot create an instance of the abstract
class or interface but we can create a reference of it.
Ex.
abstract class Watch
{
//Non-Abstract
Method
public void Alarm()
{
Console.WriteLine("Alarm
Method: This method provides Alarm features");
}
public abstract void Model();
}
class CasioWatch : Watch
{
//Abstract
Method Implementation
public override void Model()
{
Console.WriteLine("Casio
Watch model A55");
}
}
class Program
{
static void Main(string[]
args)
{
Watch w
= new Watch(); // This Line generate Error
Watch i
= new CasioWatch(); // OK
}
}
12. An Abstract class doesn't have body.
Ex.
public abstract void Model()
{
}
13. A Derived class must implement inherited abstract member.