Default Access modifiers in C#?

 Posted by Poster on 3/29/2009 | Category: OOPS Interview questions | Views: 84076
Answer:

An enum has default modifier as public

A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers:
public
internal
private
protected internal

An interface has default modifier as public

A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers:
public
internal
private

A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Nandakumarpb on: 8/20/2010 | Points: 10
Default modifiers of CLASS and STRUCT is not Private it is INTERNAL
Posted by: Poster on: 8/20/2010 | Points: 10
Oops sorry for the typo Nandakumarpb, I have corrected.

Your response is much appreciated.

Regards
Posted by: Imsharmi on: 2/10/2012 | Points: 10
Hi,

When I cheked here 'http://msdn.microsoft.com/en-us/library/ba0a1yw2(v=vs.71).aspx' it says ,default access modifier of class is private.

Regards,
Sharmi.
Posted by: Anup3005 on: 6/20/2012 | Points: 10
it's says that the default access modifier methods of class is private.....not class is private
Posted by: Nandakumarpb on: 6/20/2012 | Points: 10
For Imsharmi , Please read carefully Msdn mentioned (link which you posted) about the member access modifier ,means member in the class .
Check this link
http://msdn.microsoft.com/en-us/library/ms173121.aspx It says

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified .

Login to post response