By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,992 Members | 1,344 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,992 IT Pros & Developers. It's quick & easy.

What is the default when writing class Test

P: n/a
Hello!!

If you write private class Test {} you have a private class
If you write public class Test {} you have a public class
If you write protected class Test {} you have a protected class
If you write internal class Test {} you have a internal class

Now to my question
If you just write class Test {}
what access is it then on the class Test meaning what is the default access.

//Tony



May 14 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello Tony,

It's private by default

TJ> If you write private class Test {} you have a private class
TJ> If you write public class Test {} you have a public class
TJ> If you write protected class Test {} you have a protected class
TJ> If you write internal class Test {} you have a internal class
TJ> Now to my question
TJ> If you just write class Test {}
TJ> what access is it then on the class Test meaning what is the default
TJ> access.

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 14 '06 #2

P: n/a
Its PUBLIC by default. YOU CANNOT CREATE PRIVATE, PROTECTED OR PROTECTED
INTERNAL CLASS IN NAMESPACE.

"Michael Nemtsev" wrote:
Hello Tony,

It's private by default

TJ> If you write private class Test {} you have a private class
TJ> If you write public class Test {} you have a public class
TJ> If you write protected class Test {} you have a protected class
TJ> If you write internal class Test {} you have a internal class
TJ> Now to my question
TJ> If you just write class Test {}
TJ> what access is it then on the class Test meaning what is the default
TJ> access.

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

May 14 '06 #3

P: n/a
So many answers and all wrong...

Classes can be public or internal.
When you do not specify access modifier, classes are internal by default.

"Classes and structs are declared as internal by default unless the keyword
public is added to the class definition" [1]

[1] Access Modifiers (C# Programming Guide),
http://msdn2.microsoft.com/en-us/library/ms173121.aspx

"Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
news:48**********************************@microsof t.com...
Its PUBLIC by default. YOU CANNOT CREATE PRIVATE, PROTECTED OR PROTECTED
INTERNAL CLASS IN NAMESPACE.

"Michael Nemtsev" wrote:
Hello Tony,

It's private by default

TJ> If you write private class Test {} you have a private class
TJ> If you write public class Test {} you have a public class
TJ> If you write protected class Test {} you have a protected class
TJ> If you write internal class Test {} you have a internal class
TJ> Now to my question
TJ> If you just write class Test {}
TJ> what access is it then on the class Test meaning what is the default
TJ> access.

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not
cease to be insipid." (c) Friedrich Nietzsche

May 14 '06 #4

P: n/a
Hello Lebesgue,

certainly, class can't be private in terms of C#, but it can be named private
in terms of framework.
If look at IL code you will see "private" identifier, whether you specify
"internal" or not for class it means "almost" nothing for IL.
"almost" means that if you specify "internal" it has effect on initializing
class local variables - in that case IL dosn't create it's own variables
that mapped to the V_* and uses variable that u specified (it doesn't lost
your variables names)
L> So many answers and all wrong...
L> Classes can be public or internal.
L> When you do not specify access modifier, classes are internal by
L> default.
L> "Classes and structs are declared as internal by default unless the
L> keyword public is added to the class definition" [1]
L>
L> [1] Access Modifiers (C# Programming Guide),
L> http://msdn2.microsoft.com/en-us/library/ms173121.aspx
L>
L> "Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
L> news:48**********************************@microsof t.com...
L>
Its PUBLIC by default. YOU CANNOT CREATE PRIVATE, PROTECTED OR
PROTECTED INTERNAL CLASS IN NAMESPACE.

"Michael Nemtsev" wrote:
Hello Tony,

It's private by default

TJ> If you write private class Test {} you have a private class
TJ> If you write public class Test {} you have a public class
TJ> If you write protected class Test {} you have a protected class
TJ> If you write internal class Test {} you have a internal class
TJ> Now to my question
TJ> If you just write class Test {}
TJ> what access is it then on the class Test meaning what is the
default
TJ> access.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do
not
cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 14 '06 #5

P: n/a
Hello Altaf,

Everything depends on which angle you are looking at class :)
In terms of IL if u specify internal or nothing classes are private. I meant
that case

AN> Its PUBLIC by default. YOU CANNOT CREATE PRIVATE, PROTECTED OR
AN> PROTECTED INTERNAL CLASS IN NAMESPACE.
AN>
AN> "Michael Nemtsev" wrote:
AN>
Hello Tony,

It's private by default

TJ> If you write private class Test {} you have a private class
TJ> If you write public class Test {} you have a public class
TJ> If you write protected class Test {} you have a protected class
TJ> If you write internal class Test {} you have a internal class
TJ> Now to my question
TJ> If you just write class Test {}
TJ> what access is it then on the class Test meaning what is the
default
TJ> access.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 14 '06 #6

P: n/a
On Sun, 14 May 2006 09:08:39 GMT, "Tony Johansson"
<jo*****************@telia.com> wrote:
Hello!!

If you write private class Test {} you have a private class
If you write public class Test {} you have a public class
If you write protected class Test {} you have a protected class
If you write internal class Test {} you have a internal class

Now to my question
If you just write class Test {}
what access is it then on the class Test meaning what is the default access.


Acces modifiers in c# are by default the most restrictive.

The most restrictive modifier for elements inside a namespace is
internal. The most restrictive modifier for elements inside a class is
private.
class A //internal (Declared inside root namespace)
{
class B //private (Declared inside class a)
{
}
}

--
Marcus Andrén
May 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.