static class console and no inherited


H

Hex

public static class Console
Member of System

Summary:
Represents the standard input, output, and error streams for console
applications. This class cannot be inherited.

My question is : Why a static class can not be inherited by another
static class ?

thx in advance claudio
 
Ad

Advertisements

A

Arne Vajhøj

public static class Console
Member of System

Summary:
Represents the standard input, output, and error streams for console
applications. This class cannot be inherited.

My question is : Why a static class can not be inherited by another
static class ?

The language was defined that way.

And it is worth noting that at the IL level the class
is actually sealed.

But I assume that you really want to know why it was designed
this way.

My guess is that it is because it would not provide
much value without making things very complex.

What makes inheritance and interface implementation
really useful for non static classes is the
polymorphism.

That is not possible in the same way for static
classes.

Too little value for too many complications.

Arne
 
Ad

Advertisements

A

Arne Vajhøj

C# follows the same design as most other mainstream OOP languages (and
especially C-based ones such as C++ and Java), where static class
members are accessible only implicitly from within the class itself, or
by specifically naming the type in which the static member exists.

That is how C# does it.

Both C++ and Java allows you to call static methods "on"
an instance.

Arne
 

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