2. ABSTRACT CLASS
Definition:
The class is created for the purpose of providing common fields
and members to all subclasses then this type of class is called an
abstract class.
While we are declaring a class if we used abstract keyword
that is abstract class.
Abstract class is a collection of abstract members and non
abstract members.
3. ABSTRACT CLASS
• Syntax for Abstract class:
abstract class <class name>
{
//abstract Members;
or
//Non abstract members;
}
We can use abstract key word for Properties , events & methods
,So an abstract class can contain abstract properties ,abstract
events and abstract methods
4. ABSTRACT CLASS
Abstract Method:
Abstract members can contain only declaration part in abstract class
that means it will contain only skeleton of the member.
The definition of abstract member (or) implementation of abstract
member should be in derived class.
We should implement abstract members in derived class using
override keyword.
Syntax For Abstract method:
abstract <return type> <method name>();
Example:
abstract void display();
5. ABSTRACT CLASS
• Abstract class can not be instantiated, that means we can not
create object for abstract class.
• We have to access members using derived class object only.
Syntax for Abstract Property:
abstract <data type> <property name>
{
get;
set;
}
6. ABSTRACT CLASS
We can not declare abstract class as a sealed class because
sealed class will not inherited to derived class.
If we declare abstract class as a sealed class we can not
implement abstract members in derived class.
Example:
abstract sealed class Demo
{
}
o/p: Error
7. ABSTRACT CLASS
We can not use private access modifier for abstract class as
well as abstract members.
Because we can not access that abstract class members in
the derived class.
Example:
private abstract void display();
{
}
o/p: Error
8. ABSTRACT CLASS
• By default abstract members all are virtual .
• We can not use virtual key word for abstract members.
• Access modifier of a abstract member should be same in
the abstract class and derived class.
Ex:
public abstract void Demo
{
public void m1();
}
public class Demo1:Demo
{
public override void m1()
{;
}
}