Default Access Specifer

What is default access specifer of a class in C#? Is it internal or private?

class foo{
int Var; }

In the above code snippet. What is the default access specifier for the variable Var.

Questions by Kanike.Nihar   answers by Kanike.Nihar

Editorial / Best Answer

phanish  

  • Member Since Jul-2010 | Jul 16th, 2010


Default Access Specifier of a class is Internal and Default Access Specifier of Member Variable is Private

Showing Answers 1 - 40 of 40 Answers

prgoyal

  • Jul 14th, 2010
 

It is public by default. You can access the attributes of a class by creating an instance of class and that instance let you access value of attributes.

  Was this answer useful?  Yes

There are 5 types of access Specifiers are there in C#:
1. public
2. private
3. protected
4. internal
5. protected internal

Now the question is which is the default access specifier. The answer is : PRIVATE
Whether its a class or function, the default specifier is always private.

C# has TYPES. Like Class, Interface,Structure,Enums and Delegates. Each TYPE you declares has default access specifier as INTERNAL. Now with in these TYPES if you declare any nested TYPES or declare any variable or any member function then it will have default access specifier as PRIVATE.

  Was this answer useful?  Yes

hazi05

  • Aug 21st, 2010
 

Internal is the default access specifier for a class, private is the default access specifier for a data member of a class

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions