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

 The differentiate between abstract class, sealed class, and interface are as follows:-

Abstract Class

A class is said to be an abstract class if we can’t instantiate an object of that class without creating its sub-class. Such class only exists as a 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 subclasses. Classes inheriting an Abstract Class must provide a 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 a compile-time error as it attempts to inherit Sealed Class

{

}


Interface

An interface is a named collection of methods declaration without implementations/definition. An interface defines what a class must do but not how it does. To declare an interface, we use the interface keyword. A class that implements the 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>


The task of Object Relational Mapper

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

Comments

Popular posts from this blog

What are different steps used in JDBC? Write down a small program showing all steps.

Discuss classification or taxonomy of virtualization at different levels.

Pure Versus Partial EC