i want to knw the diff between static class and abstractclass .i would appreciate if its followed by

P

pinki panda

i want to knw the diff between static class and abstract class .i would appreciate if its followed by example
 
M

Marc Gravell

A static class *only* defines static members. You can never have an
instance of a static class, nor can you ever subclass it.

An abstract class can never be instantiated "as is", but is designed to
be subclassed. It should be expected that there be be instances of
*subclasses* of the type.

For example Stream is abstract : it makes no sense to just have "a
stream": where would the data come from / go to? You need some actual
real ["concrete"] implementations in order for it to make sense: a
FileStream, a NetworkStream, a MemoryStream etc. However, most of your
code only needs to know about Stream - it rarely needs to know what
/kind/ of stream it is.

Marc
 
G

GArlington

i want to knw the diff between static class and abstract class .i would appreciate if its followed by example

How about the RTFM?
Try to create and compile and run them...
 
J

Jon Skeet [C# MVP]

i want to knw the diff between static class and abstract class .i would appreciate if its followed by example

An abstract class is one which can't be directly instantiated. It
usually has some abstract methods which must be implemented by classes
further down the hierarchy:

public abstract class Foo
{
public abstract void DoSomething();

public void NormalMethod()
{
DoSomething();
}
}

A static class is one which can never be instantiated. You can't use
this as the type of a parameter, or a variable, or a type parameter.
It has no constructors (unlike normal classes, which gain a public
parameterless constructor automatically if you don't specify any
constructors). It's not allowed to have any instance members. It's
usually used for "helper methods". Extension methods (new to C# 3.0)
have to be in non-nested static classes.

public static class StringUtil
{
public static string Reverse(string original)
{
// Whatever
}
}

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top