22.6.13

C# code Abstract method- In few simple straightforward steps

Abstract 

'abstract' is a keyword in C# programming language which help us to create generalize version of any method, which is must to be override in its derived class. However it is similar to interface thing but still it gives many benefits of using this to its user.... lets see how it is similar to interface or where it differ...



when we talk about abstract methods in few more simple words those methods which don't have implementations is known as abstract methods.

Straightforwardly, few things about abstract.
-> You can not precede 'abstract' keyword before any member variable.
-> Whenever you precede abstract to any method you need not to give it s implementation.
-> Whenever you include one or more abstract method in any base class you must define that class as abstract too.
-> After this, where ever you are inheriting this class, it is necessary to implement this method .
-> You cannot instantiate an abstract class, i.e. you can't create object of a base class.
-> This is because abstract classes doesn't provide full implementation.
-> Whichever class you inherit any abstract class, abstract method must be override.
-> If you don't want to provide implementation for one abstract method defined in base class, precede that method in the derived class as abstract too.
-> Now again, provide it's implementation in next derived class, it is must.
-> Repeat this procedure unless you don't provide implementation for method(s) that is defined as abstract in base class. 

-> You can declare any method abstract in following ways:-

public abstract type name() 
or 
abstract public type name()

-> to override

public override type name() 
or
override public type name() 

Well interfaces are the way to implement multiple inheritance and which ever number of methods/ properties, indexers (... but not field) you have defined here must be implement in the derived class otherwise C# compiler will throw an error.

Thanks

[Note:

* You all are welcome to express your views as comment in the box given below of this post. 

* I have not made any special conditions to write here your comment but you may write whatever your heart speak out loud in your inner-self.

* This blog space is continuously in writing/edit mode, kindly keep visiting for a full version]

Post related to CSharp programming

No comments:

Post a Comment

Search This Blog

Let make your friend aware about this post