?

Log in

No account? Create an account

Previous Entry | Next Entry

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”.

interface IDbCompulsory
{
void ExecSql();
}
public class SQLServer : IDbCompulsory
{
public void ExecSql()
{
// Here code for firing SQL Server SQL statements
// are written
}
}
public class Oracle : IDbCompulsory
{
public void ExecSql()
{
// Here code for firing Oracle SQL statements
// are written
}
}
 

Abstract classes: -

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.

public abstract class DatabaseCommon
{
}
public class SQLServer : DatabaseCommon
{
}
public class Oracle : DatabaseCommon
{
}


Also see another .NET interview questions video on implement interfaces with same method names in C#: -

Copy right www.questpond.com

Tags

Latest Month

September 2017
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
Powered by LiveJournal.com