February 23, 2020

Abstract class vs Interface


Abstract class vs Interface: 

1. A class can implement any number of interfaces but a subclass can at most use only one abstract class.
2. An abstract class can have non-abstract Methods(concrete methods or full method definition) while in case of Interface all the methods has to be abstract.
3. An abstract class can declare or use any variables while an interface is not allowed to do so.

4. An abstract class can have constructor declaration while an interface can not do so.

5. An abstract Class is allowed to have all access modifiers for all of its member declaration while in interface we can not declare any access modifier(including public) as all the members of interface are implicitly public.

=========================================================================

Dictionary vs Hashtable
 
Dictionary:

– Dictionary is a generic type which means we can use it with any data type.
– Only public static members are thread safe.
– It returns error if we try to find a key which does not exist.
– It is faster than a Hashtable because there is no boxing and unboxing.

Hashtable:

– Hashtable is not a generic type.
– All the members in a Hashtable are thread safe.
– It returns null if we try to find a key which does not exist.
– It is slower than dictionary because it requires boxing and unboxing.