What is an Abstract Class?

An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be subclassed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

What is an Interface?
An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.

Both Together
When we create an interface, we are basically creating a set of methods without any implementation that must be overridden by the implemented classes. The advantage is that it provides a way for a class to be a part of two classes: one from inheritance hierarchy and one from the interface. When we create an abstract class, we are creating a base class that might have one or more completed methods but at least one or more methods are left uncompleted and declared abstract. If all the methods of an abstract class are uncompleted then it is same as an interface. The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes. There are some similarities and differences between an interface and an abstract class that I have arranged in a table for easier comparison: Feature Multiple inheritance Default implementation Interface A class may inherit several interfaces. An interface cannot provide any code, just the signature. Abstract class A class may inherit only one abstract class. An abstract class can provide complete, default code and/or just the details that have to be overridden. An abstract class can contain access modifiers for the subs, functions, properties An abstract class defines

Access Modfiers

An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public Interfaces are used to

Core VS Peripheral

Operation on StringBuilder object is faster than String operations. an insertion is done on the existing string. Fast Speed Adding functionality (Versioning) If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. No fields can be defined in interfaces If various implementations are of the same kind and use common behaviour or status then abstract class is better to use. The most common operation with a string is concatenation. the first string is combined to the other string by creating a new copy in the memory as a string object. This means. Homogeneity If various implementations only share method signatures then it is better to use Interfaces. Requires more time to find the actual method in the corresponding classes. This process is a little long. An abstract class can have fields and constrants defined Fields and Constants Difference between string and string builder Both String and StringBuilder are classes used to handle the strings. If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. But the main difference is: ToString() raise exception when the object is null . When we use the "String" object to concatenate two strings. This activity has to be performed very efficiently. as the copy is done to the same location. Abstract class the core identity of a class and there it is used for objects of the same type.ToString() Both perform the same function. In other words both Human and Vehicle can inherit from a IMovable interface.Feature Interface define the peripheral abilities of a class. Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed. Difference Between ToString() vs Convert. Hence we say "Strings are immutable". and then the old string is deleted. the Append method is used. When we make use of the "StringBuilder" object.

15. 4. 14. 12. 5. type safe programming language.ToString(). if object is null. are bound checked. 9. 3. 8.ToString() return string. Value types (primitive types) are initialized to zeros and reference types (objects and classes are initialized to null by the compiler automatically. 2.So in the case of object. We may develop Console application. Varying Integer. Allows restricted use of native pointers. Pointers are missing in C#. automatic memory management and a lot. Boolean values are pure true or false values in C# so no more errors of "="operator and "=="operator. It supports garbage collection. CONCLUSION C# is a modern. It aims to combine the high productivity of Visual Basic and the raw power of C+ +. In C# we cannot perform unsafe casts like convert double to a Boolean. C# is a simple. 6. Windows application. Convert. object oriented language derived from C++ and Java. "==" is used for comparison operation and "=" is used for assignment operation. C# allows the users to use pointers as unsafe code blocks to manipulate your old code. In C# there ranges of is no the usage primitive of types "::" like or "->" operators.Empty in case of null object. Floats etc. object oriented language that enables programmers to quickly and easily build solutions for the Microsoft . Unsafe operations such as direct memory manipulation are not allowed. Overflow of types can be checked. and Web application using C#.NET platform. 11. it raise NullReferenceException. Arrays are zero base indexed and 13. . modern. Integer values of 0 and 1 are no longer accepted as Boolean values. 10. Some notable distinguishing features of C# are: 1. 7.

a single space in memory is allocated to store the value. A class can have a default constructor A structure cannot have any without any parameter. a class is defined by using the class keyword. in arrays. For A struct can be created without using example. For example. Reference types are stored on heap. When a value type is created. example. A class is more efficient when used in A structure is more efficient when used collections. cannot be initialized in a struct. stud_report). or struct. For StudentReport(stud_enroll. also supports destructors. Assigning a variable of type value to another variable of type value COPIES that value Reference types A variable of type reference. A structure does not support inheritance A class can be inherited from a class or and cannot be inherited from any class struct. Differences between a value types and reference types in C#: Value types A variable that is of type value directly contains a value. An object is created in memory and then handled through a separate reference.} A class is a reference type and its object is A structure is a value type and its object created on the heap. . but does not make a copy of the object. stud_name. Value types cannot contain the value null. public class StudentReport{…. default. All members of a class are private by All members of a structure are public by default. It also cannot have destructors. StudentReport StudRepo = new the new keyword. public struct StudentReport{….} Structure In C# language. Reference types can contain the value null. Assigning a variable of type reference to another variable of type reference copies that reference (it tells the new object where the place in memory is). A class cannot be created without using the new keyword. points to a place in memory where the actual object is contained. For example. StudentReport StudRepo. which is provided by parameterless constructor or the default the common language runtime (or CLR). is created on the stack.Differences between a class and a structure in C#: Class In C# language. It constructor that is provided by the CLR. Value types are stored on the stack. a structure is defined by using the struct keyword. An instance field or a member variable can An instance field or a member variable be initialized in a class.

3.: int.Collections namespace. 2.: classes.g. 1. objects. ArrayList is in the System. It has the ability for classes to provide different implementations of methods that are called through the same name. 4. Polymorphism and its types: Polymorphism provides following features: • • It allows you to invoke methods of derived class through base class reference during runtime. It is also called late binding. Runtime polymorphism/Overriding Compile Time Polymorphism Compile time polymorphism is method and operators overloading. Polymorphism is of two types: 1. 5. Char[] vowel=new Char[].g. Method overriding is called runtime polymorphism. strings. float. Array is in the System namespace The capacity of an Array is fixed An Array is a collection of similar items An Array can have multiple dimensions The lower bound of an Array can be set. In method overloading method performs the different task at the different input parameters. It is also called early binding. Runtime Time Polymorphism Runtime time polymorphism is done using inheritance and virtual functions. . char. ArrayList can increase and decrease size dynamically ArrayList can hold item of different types ArrayList always has exactly one dimension The lower bound is always zero.E. Compile time polymorphism/Overloading 2. arrays Differences between array and ArrayList in C#: ARRAY ARRAYLIST ArrayList a_list=new ArrayList(). structures. 6. enumerations e. bool.

. Overloading a method simply involves having another method with the same prototype.When overriding a method. you change the behaviour of the method for the derived class.

Sign up to vote on this title
UsefulNot useful