By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

static classes, nested class, public class

P: n/a
Would you quickly remind me the difference between, regular class,
static class, and nested class?

Thanks
Nov 2 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"puzzlecracker" <ir*********@gmail.comwrote in message
news:5d**********************************@n33g2000 pri.googlegroups.com...
Would you quickly remind me the difference between, regular class,
static class, and nested class?
A 'regular' class my be used to create object instances for which the class
is the type. Each instance will hold a set of fields which hold values for
that instance only. A class may also contain static members which may be
fields, properties or methods which are common across all instances of the
class. Such static members are accessed through the Type name.

A class marked as static may only contain static members and instances of a
static class cannot be created.

A nested class is a class that is defined inside another class. One
difference that a nested class has from a regular class is that it may be
private where it can only be used inside the class definining it, whereas a
regular class cannot be private.

--
Anthony Jones - MVP ASP/ASP.NET

Nov 2 '08 #2

P: n/a
A 'regular' class can contain any kind of members (fields, methods,
properties, events et cetera), be it static or accessible through an
instance only. A static class, however, can only contain static members and
this is especially useful when the design you choose assumes that this class
cannot or should not be instantiated, for example a set of helper functions.

A nested class is defined within the scope of its 'parent' class--it may be
private or accessible to external classes. You might want to choose to do
this if your design assumes a hierarchical relationship between the two (or
more) classes.
--
Stanimir Stoyanov
http://stoyanoff.info

"puzzlecracker" <ir*********@gmail.comwrote in message
news:5d**********************************@n33g2000 pri.googlegroups.com...
Would you quickly remind me the difference between, regular class,
static class, and nested class?

Thanks
Nov 2 '08 #3

P: n/a
Anthony Jones wrote:
"puzzlecracker" <ir*********@gmail.comwrote in message
news:5d**********************************@n33g2000 pri.googlegroups.com...
>Would you quickly remind me the difference between, regular class,
static class, and nested class?

A 'regular' class my be used to create object instances for which the
class is the type. Each instance will hold a set of fields which
hold values for that instance only. A class may also contain static
members which may be fields, properties or methods which are common
across all instances of the class. Such static members are accessed
through the Type name.
A class marked as static may only contain static members and
instances of a static class cannot be created.

A nested class is a class that is defined inside another class. One
difference that a nested class has from a regular class is that it
may be private where it can only be used inside the class definining
it, whereas a regular class cannot be private.
Also, being a member of the containing class, it has permission to use
private and protected members of the containing class. Static members are
of course accessible directly, and instance members can be explicitly
referenced using a reference to an object derived from the containing class.
Note that these are NOT Java inner classes, there is no implicit reference
to an instance of the containing class.

And Java uses the static keyword very differently with member classes --
Java defaults to defining an "inner class" and you use "static" to get a
normal nested class. C# always gives you a nested class.
Nov 3 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.