Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




.NET OOPS interview questions: - What is an Interface? Do interface have accessibility modifier? Can we create an object of abstract class or an 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”.

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                     

}

}


Do interface have accessibility modifier?


All elements in Interface should be public. So no accessibility modifier is required.

Can we create an object of abstract class or an interface?


No.

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

Helpful Website Url
http://questpond.com/
Share this article   |    Print    |    Article read by 8952 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles: No related article
Related Interview Questions: No related interview question