Abstract class is useful in senario where you want to provide base case which cannot be intiated , but have some implementation which is common to child class.
Normally thre is question what is different between interface and abastrac calss ?
Both are mean to provide contact , that means they provide set of methods that must be implented by child which inherits them.
But inheritance have all method public and doesnt have implementation for any method. you also not able to create instace of interface directly.
Example of Customer class
public abstract class Customer
{
public String Name {get; set;}
public int id {get; set;}
public abastract int CalculateRewardPoint();
public void printCustomer
{ Console.Wrtieln(Name + " " + id.Tostring());
}
}
public class RetailCustomer : Customer
{
public override CalculateRewardPoint()
{ //implementation }
}
public class RetailCustomer : CorporateCustomer
{
public override CalculateRewardPoint()
{ //implementation }
}
Here in this example CalculateRewardpoint method is going to implemented by child but Printcustomer having same logic for both child i.e. parent class abastract class provide common method implementation
Abstract class is a special type of class which cannot be instantiated and acts as a base class for other classes. Abstract class members marked as abstract must be implemented by derived classes.
Govinda Rajulu YemineniPosted Jul 27, 2015, 1:50 AM
Pranay RanaPosted Jul 25, 2015, 10:35 AM
Console.Wrtieln(Name + " " + id.Tostring());
Rajeesh MenothPosted Jul 25, 2015, 9:16 AM