IN ABSTRACT CLASS we can create instance through anobject : example given below (but there is no use just to know this giving you)
Any where people simply explaining we can create instane/object for abstract class , there is no explanation , but i found something just giving you can try and understance.
- public abstract class AbstractBankBalance
- {
- public abstract int ClosingBalance();
- public abstract void showme();
- }
- public class sbi : AbstractBankBalance
- {
- public override int ClosingBalance()
- {
- return 1000;
- }
- public override void showme()
- {
- Console.WriteLine(this.GetType().Name.ToUpper());
- }
- }
- public class icci : AbstractBankBalance
- {
- public override int ClosingBalance()
- {
- return 2000;
- }
- public override void showme()
- {
- Console.WriteLine(this.GetType().Name.ToUpper());
- }
- }
- IN CONSOLE APPLICATION JUST COPY AND PAST AND RUN WILL WORK,
- static void Main(string[] args)
- {
- AbstractBankBalance[] bankarray = new AbstractBankBalance[2];
- bankarray[0] = new sbi();
- bankarray[1] = new icci();
- foreach (var item in bankarray)
- {
- Console.WriteLine("ABSTRACT CLASS SAME BUT THROUGH A OBJECT THAT IS ARRAY " + item.ClosingBalance());
- item.showme();
- }
- Console.ReadKey();
- }
- }