1.

What are the types of classes in C#?

Answer»

Class is an entity that ENCAPSULATES all the PROPERTIES of its objects and instances as a single unit. C# has FOUR types of such classes:

  • Static class: Static class, defined by the keyword ‘static’ does not allow inheritance. Therefore, you cannot create an object for a static class.

Sample code:

static class classname  {  //static data members  //static methods  }
  • Partial class: Partial class, defined by the keyword ‘partial’ allows its members to partially divide or share source (.cs) files.
  • Abstract class: Abstract classes are classes that cannot be instantiated where you cannot create objects. Abstract classes work on the OOPS concept of abstraction. Abstraction helps to extract essential DETAILS and hide the unessential ones.
  • Sealed class: Sealed classes are classes that cannot be inherited. USE the keyword sealed to restrict access to users to inherit that class. 
     
sealed class InterviewBit{ // data members // methods . . .}


Discussion

No Comment Found