Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

C#/.NET interview questions: - What are Abstract Classes and Interface? Distinguish between Abstrac

C#/.NET interview questions: - What are Abstract Classes and Interface? Distinguish between Abstract Classes and Interface?

Abstract class: -

Abstract class is a half defined parent class. The full implementation of abstract class is defined by the child classes.

For example below code snippet shows a simple abstract class / half defined class called “DatabaseCommon” and later the concrete classes i.e. “SQLServer” and “Oracle” inherit and define a complete implementation for the same.

To define an abstract class we need to use the abstract keyword.

code 1

Interface: -

Interface is a contract that defines the signature of the functionality. It looks like a class but has no implementation. It has only empty definition of methods, functions, events, and indexer.

Interfaces provide forced implementation. For instance in the below code snippet we have created a simple interface called as “IDbCompulsory”. The below classes who implement interface “IDbCompulsory” has to provide implementation for “ExecSql”.

code 2

Differences between Abstract Class and Interface

table

Also see the following .NET interview questions video on implementing interfaces with same method names in C#:-

Tags: .net, .net interview questions, abstract class, csharp interview questions, interface, it interview questions with answers, programming interview questions
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments