NET Centric Computing - Old Questions

7. Differentiate between abstract class, sealed class and interface. What is the task of Object Relational Mapper?

5 marks | Asked in Model Question

Abstract Class

A class is said to be abstract class, if we can’t instantiate object of that class without creating its sub class. Such class only exists as parent of derived classes from which objects are instantiated. Abstract Class contains at least one abstract method. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the abstract method.

Example: 

using System;

namespace ConsoleApp

{

  class Program

  {

     static void Main(string[] args)

     {

        Demo d;     //d is Reference Type variable of Abstract Class Demo

        Demo1 d2 = new Demo1();

        d = d2;

        d.Display();

        Console.ReadKey();

      }

    }

    abstract class Demo     //Abstract Class

    {

        public abstract void Display();     //Abstract Method

    }

    class Demo1 : Demo     //Concrete Class

    {

        public override void Display()

    {

        Console.Write("Derived Class Method Invoked");

    }

  }

}

Sealed Class

Sealed classes are used to restrict the users from inheriting the class. A class can be sealed by using the sealed keyword or modifier. This keyword tells the compiler that the class is sealed, and therefore, cannot be extended. No class can be derived from a sealed class.

Example:

class Demo

{

}

sealed class Demo1:Demo

{

}

class Demo2 : Demo1     //This Statement generates compile time error as it attempts to inherit Sealed Class

{

}

Interface

An interface is a named collection of methods declaration without implementations/definition. Interface define what a class must do but not how it does. To declare an interface, we use interface keyword. A class that implements interface must implement all the methods declared in the interface.

Syntax: Creating Interface

interface <interface_name >

{

    //Methods Declaration

}

Syntax: Implementing Interface

class class_name :< interface_name>


An Object Relational Mapper (ORM) is an application or system that support in the conversion of data within a relational database management system  (RDBMS) and the object model that is necessary for use within object-oriented programming.