Adhi Venkatesh

Adhi Venkatesh

  • NA
  • 155
  • 3.4k

Creating Abstract class instance

May 31 2019 12:26 PM
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. 
  1. public abstract class AbstractBankBalance  
  2. {  
  3. public abstract int ClosingBalance();  
  4. public abstract void showme();  
  5. }  
  6. public class sbi : AbstractBankBalance  
  7. {  
  8. public override int ClosingBalance()  
  9. {  
  10. return 1000;  
  11. }  
  12. public override void showme()  
  13. {  
  14. Console.WriteLine(this.GetType().Name.ToUpper());  
  15. }  
  16. }  
  17. public class icci : AbstractBankBalance  
  18. {  
  19. public override int ClosingBalance()  
  20. {  
  21. return 2000;  
  22. }  
  23. public override void showme()  
  24. {  
  25. Console.WriteLine(this.GetType().Name.ToUpper());  
  26. }  
  27. }  
  28. IN CONSOLE APPLICATION JUST COPY AND PAST AND RUN WILL WORK,  
  29. static void Main(string[] args)  
  30. {  
  31. AbstractBankBalance[] bankarray = new AbstractBankBalance[2];  
  32. bankarray[0] = new sbi();  
  33. bankarray[1] = new icci();  
  34. foreach (var item in bankarray)  
  35. {  
  36. Console.WriteLine("ABSTRACT CLASS SAME BUT THROUGH A OBJECT THAT IS ARRAY " + item.ClosingBalance());  
  37. item.showme();  
  38. }  
  39. Console.ReadKey();  
  40. }  
  41. }  

Answers (2)