471,336 Members | 1,230 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Difference between "class" and "public class"

Hi everyone,

can someone point out the difference between defining a class with the
public access modifier and just leaving it as it is (default in vs.net
"class")

I think that the default access modifier applied if one isn't defined;
so class would in fact be read as "private class" when it's compiled,
but that isn't the case.

When the code below code compiles, it will throw an error for c3, but
not for the other two classes. The fact that they're in different
namespaces also rules out that "class" is only visible within a
namespace.

I thought it might be only assembly-wide visible if defined without
the public access modifier, but, uh, I guess that's what the internal
keyword is for.

Thanks,
Matt

namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var c1 = new n1.c1();
var c2 = new n2.c2();
var c3 = new n3.c3();
}
}
}

namespace n1
{
class c1
{
}
}

namespace n2
{
class c2
{
}
}

namespace n3
{
private class c3
{
}
}
Aug 21 '08 #1
3 3230
"private class" makes no sense at the namespaec level; the default
access modifier is "internal".

So "class" (at the namespace level) is "internal class".

Marc
Aug 21 '08 #2
To clarify - for nested class the default is "private".

Marc
Aug 21 '08 #3
On Aug 21, 12:00*pm, Marc Gravell <marc.grav...@gmail.comwrote:
"private class" makes no sense at the namespaec level; the default
access modifier is "internal".

So "class" (at the namespace level) is "internal class".

Marc
Ah, Cheers!
Aug 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by dpr | last post: by
14 posts views Thread by mshetty | last post: by
reply views Thread by Kenneth Baltrinic | last post: by
9 posts views Thread by Kobe | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.