Solved

public vs private classes

Posted on 2003-10-25
5
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

626 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