Share Blog

Monday, October 26, 2015

Difference Between Abstract Class And Abstract Method in C#

Abstract Class:- 
we use 'abstract' keyword to implement the concept of abstract class. 'Abstract class' can only inherited by other class.we can not create objects of 'abstract class' directly. When any  'abstract class' is inherited by other class then we create the objects of that derived class.We can not create objects of  'abstract class' because methods of  'abstract class' only declare but not define.

    If any class will inherited the  'abstract class' then that derived class will give the body of the  'abstract class'member.
Some characteristics of an  'abstract class' are:-
§  It can not be instantiate directly.
§  It can have abstract members.
§  we can not apply a sealed modifier to it.

Abstract Method:-
when we know what will happen but do not know how it happen ,we just only declare the method but do not define the method. In that case abstract keyword declare with method.
when an instance method declaration includes the modifier abstract,the method is said to be an
 abstract method.
Some characteristics of abstract method are:-

  It can not have implementation.
  Its implementation must be provide in non-abstract derived classes by overriding the method.
  It can be declared only in abstract classes.
  It can not take either static or virtual modifier.
  An abstract declaration is permitted to override a virtual method.


Saturday, October 10, 2015

Difference Detween Value type and Reference type in C#


1.   There are following difference between Value type and reference type on the basis of Storage.
2.     Value type store within stack memory and reference type store within heap memory.
3.     Structure,all primitive data type except string,enum are the example of value type.Class,string,array,delegate,interface is the example of reference type.
4.     Value type directly store values within stack but reference type contains reference object of value which store in heap.
5.     when value type is copy to another value type then actual value is copy,but when reference type is copy to another reference type then reference address of value is copy .
6.     Value type can be initialize with zero(0) and reference type initialize with NULL.