Access keywords with classes

  • Thread starter Thread starter Dylan Parry
  • Start date Start date
D

Dylan Parry

Hi,

I understand how access keywords like public, private, protected etc
work when it comes to using them in method declarations, but how do they
work when it comes to class declarations?

For example, what would the following mean:

namespace example {
public class Foo {
...
}

private class Bar {
...
}

protected class FooBar {
...
}
}

Why would I use any of the above instead of just declaring my classes
with like "class Foo"?
 
How about the internal class?
class example { public class Foo {} private class Bar{} } ...
then you have class ExtendedExample : .... you will see the difference
 
Hi,

You can't have a private class directly within in a namespace. It
would mean that the class is not visible to anything.. if the class
isn't visible to anything, how could it ever be used? Same goes with
protected. You'd actually get compiler errors if you try to have a
private or protected class nested at the namespace level.

You could have an internal class however; that would be a class which
only members of the same assembly could see.

HTH
Andy
 
Pondering the eternal question of "Hobnobs or Rich Tea?", Andy finally
proclaimed:
You could have an internal class however; that would be a class which
only members of the same assembly could see.

Ah I see. It's starting to make sense now, thanks.
 
Pondering the eternal question of "Hobnobs or Rich Tea?",
(e-mail address removed) finally proclaimed:
How about the internal class?

Yes, that's something else that I'm totally ignorant of! :) From Andy's
reply I'm starting to understand it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top