Class Vs Interface in C#
A Class is a specification of how to construct Objects from the same Class . It is a type of blueprint or prototype from which individual Objects are created. We can say a Class is a template that describes the kinds of state and behavior that Objects of its type support.
In Object Oriented Programming (OOP) terms, we can say that a Toyota car is an instance of the Class of Objects known as Car. A Class is like the blueprint for a Car. Using this blueprint, you can build as many Cars as you like. Each car you build is an Object of the Class Car. Each Car also has a number, of course. If you want to tell someone which is your car, you give them the number for identifying it. This number is called Object's reference .
An Interface provides a contract specifying how to create an Object, without caring about the specifics of how they do the things. An Interface is a reference type and it included only abstract members such as Events, Methods, Properties etc. and it has no implementations for any of its members.
When a Class implements an Interface are forced by the compiler to write the methods and Properties that the Interface has defined. That is, if you implement an Interface in your Class you have to declare all of the Interface's Events, Methods, Properties in your Class. An Interface can have only Abstract methods and Constants , which are always implicitly public, static, and final.
A Class has both definition and an implementation whereas Interface only has a definition.
A Class can be instantiated but an Interface cannot be instantiated You can create an instance of an Object that implements the Interface.
A Class is a full body entity with members, methods along with there definition and implementation. An Interface is just a set of definition that you must implement in your Class inheriting that Interface.
- Difference between a Value Type and a Reference Type
- System level Exceptions Vs Application level Exceptions
- Difference between sub-procedure and function
- What does the term immutable mean
- What does the keyword static mean
- this.close() Vs Application.Exit()
- Difference between a.Equals(b) and a == b
- Difference between Hashtable and Dictionary
- Difference between Exception and Error
- C# Dictionary Versus List Lookup Time
- Why does C# doesn't support Multiple inheritance