allowing to generate instances of them.Defining a class
as abstract,we can make it secure.so c# provides secure
OOP programming.
look at the following example-
//base class
abstract public class BankAccount{
private string customerName;
private string accountNumber;
private double banlance;
public BankAccount(string accountNumber, string customerName)
: this()
{
this.accountNumber = accountNumber;
this.customerName = customerName;
}
public string Deposit(double amount){ //codes }
public virtual string Withdraw(double amount{ //codes }
//derived class
public class SavingsAccount: BankAccount{
private double interestRate;
public SavingsAccount(string accountNumber, string customerName,
double interestRate) : base(accountNumber, customerName)
{
this.interestRate = interestRate;
}
public override string Withdraw(double amount){ //codes }
}
public class MainClass{
public static void main(){
BankAccount svAcc=new BankAccount("Sv-203736","mridul");//wrong
SavingsAccount svAcc2 = new SavingsAccount("Sv-203736",
"mridul", 5.5);
in the first line of the main method in the above example,we
can't initiate BankAccount object because it was declared as
abstract so it's not instantiable.we can use the functionality
of that base class by the derived classes like SavingsAccount
class in the above example.we can have the private members,
constructors,and methods from the base class-BankAccount to
the derived class SavingsAccount.In this way c# programs are
protected.