Solved

public vs private classes

Posted on 2003-10-25
5
334 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 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