.Net Interview Question:-Declare Interfaces as private?

Sometimes I am surprised with some questions which come up during .NET interview and this one is one of them. I really do not understand why people ask such questions and how useful it is practically.

Most of the developers jump to the conclusion and say “NO”.

Let me first prove that how the developer are also right by saying that
Interfaces cannot be declared as private and later we will see that how they are also wrong(incorrect).

Now, let first declare an interface as private and try to compile it and see that what the compiler says about it.

private interface I1
{

}

In the above diagram you can see that the compiler throws an error saying that Elements defined in a namespace cannot be explicitly declared as private.

Now, let’s prove the second point that interfaces can also be declared as private.

In the below code snippet you will see that I have declared the interface as private and try to build the solution, will see that what the compiler has to say about it.

class MyClass
{
private interface I1
{ 
}
}

In above diagram you can see that now the compiler has successfully build solution without throwing the error this means that we can declare Interfaces as private also but the interfaces declared as private should be declared inside the class.

Note: – To declare Interfaces as Private you need to declare it inside the class.

Following is the video which shows that how the questions are asked C# and .NET interviews.



Please click here to see more interview questions and answers for .NET

Regards,

Visit Authors blog for more Most asked Dotnet interview questions

Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s