Solved

public vs private classes

Posted on 2003-10-25
5
332 Views
Last Modified: 2010-04-16
I need a "for dummies" anwser of the difference between public and private classes.
0
Comment
Question by:chilled2003
5 Comments
 

Author Comment

by:chilled2003
ID: 9621167
ok figured this one out, what does the "static" mean in public static void Main() ?
0
 
LVL 1

Accepted Solution

by:
marcin1 earned 50 total points
ID: 9621188
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
 

Expert Comment

by:soft_developer
ID: 9621334
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
 

Author Comment

by:chilled2003
ID: 9621483
Thanks :)
0
 
LVL 1

Expert Comment

by:kellycoinguy
ID: 9623901

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question