Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

public vs private classes

I need a "for dummies" anwser of the difference between public and private classes.
0
chilled2003
Asked:
chilled2003
1 Solution
 
chilled2003Author Commented:
ok figured this one out, what does the "static" mean in public static void Main() ?
0
 
marcin1Commented:
There are two places where you can put your class definition:

A. Inside the namespace
B. Inside other class (nested classes)

A. This is the regular way to define classes:

namespace MyNamespace
{
      class MyClass {...}
}

In front of the class keyword you can put one of the access modifiers:

public   - the class is visible everywhere
internal - the visibility of the class is restricted to the current assembly

So if you have two projects, and you define a public class in one of them,
you can use this class in the second project. If you don't want this (you want
to hide your class), you use internal keyword.

B. If you define class A, and you want to define a helper class, you can
do it inside the body of class A:

namespace MyNamespace
{
      class A
      {
            ...
            public class Nested {...}
            ...
      }
}

In this case you can use one of the following access modifiers:
public, protected, internal, private.

They work the same way as put in front of the properties or fields.

Short explanation:
public - the nested class is visible outside class A
protected - the nested class is visible only inside class A and it
      is visible in classes which derive from A
private - the nested class is visible only inside class A and it
      is NOT visible in classes which derive from A
internal - the class is visible only in the current assembly
0
 
soft_developerCommented:
in simple,
A public class can be instantiated by any object in the application
and
A Private Class can be created only by objects of its own type or by types that it nested off.

dzelters.
0
 
chilled2003Author Commented:
Thanks :)
0
 
kellycoinguyCommented:

static on a function means that you don't need an object to invoke the function. It also implies that inside the function, there is no access to "this", although static members are available.

-Kelly
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now