what is abstract class?

 Posted by Pradeep Raturi on 3/5/2013 | Category: C# Interview questions | Views: 2946 | Points: 40

An abstract class contains abstract and non abstract method.we can declare it by using keyword abstract.
The abstract keyword allows us to create any class and its member , that may be incomplete and must be implemented in a derived.
Using abstract class multiple derived classes can share definition of base class.

Lets take an example -
Suppose we are building a house, where we want All room must be same area.. what we will do ?
we will make a method ,Suppose it is RoomArea() and implements its body ..here we have forced to architect that All room must be equal in Area therefore we have made method and its definition.
Lets take other situation , Now we move to door's color.. This time we left it over architect,he is free to Apply any color of his choice on door.we are not interested in color.
what we have done here ,we have bounded to architect that method should be our choice, so i am giving you its body but i am not interested in door's color so you can implement it in your way.
abstract class House
public void RoomArea()
{ // body ...All room must be equal in area
// it is normal method
abstract public void DoorColor(); // Abstract method

Few important points about abstract class -
1. We can not use abstract class without inheriting it.
2. Only abstract members are possible in abstract class.
3. Abstract class can have constructor.
4. We Can not create direct object of abstract class.
5. Any Class derived fro an abstract class must implement all the abstract members of the class by using the override keyword unless the derived class itself abstract.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response