static


N

nicol

Hi all
I think I can not understand the exact usage of static


using System;
namespace ConsoleApplication119
{
class Program
{
static void Main(string[] args)
{
// student p =new student ();
}
}
static class student
{
public static student() // error+++++

{
Console.WriteLine(" parent class");
}
}
static class me : student // error****************
{

}
}
Error 1 Static classes must derive from object.
Error 2 access modifiers are not allowed on static constructors
Thanks . . .
 
Ad

Advertisements

A

Arne Vajhøj

I think I can not understand the exact usage of static

using System;
namespace ConsoleApplication119
{
class Program
{
static void Main(string[] args)
{
// student p =new student ();
}
}
static class student
{
public static student() // error+++++

{
Console.WriteLine(" parent class");
}
}
static class me : student // error****************
{

}
}
Error 1 Static classes must derive from object.
Error 2 access modifiers are not allowed on static constructors

The error texts seems clear to me.

And makes sense.

Since a static constructor is not called from any code, then
access modifiers does not make sense.

Since a static class can only contain static methods, then
inheriting from another class does not make much much sense
either.

Arne
 
Ad

Advertisements

G

Göran Andersson

nicol said:
Hi all
I think I can not understand the exact usage of static


using System;
namespace ConsoleApplication119
{
class Program
{
static void Main(string[] args)
{
// student p =new student ();
}
}
static class student
{
public static student() // error+++++

{
Console.WriteLine(" parent class");
}
}
static class me : student // error****************
{

}
}
Error 1 Static classes must derive from object.
Error 2 access modifiers are not allowed on static constructors
Thanks . . .

You should not make the "student" and "me" classes static, as you want
to create instances of them.

The constructor should not be static either. A class can have a static
constructor, but that's not used for creating instances but to
initialise static members.
 

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

Similar Threads

? 7
inheritance problem 2
error :( 4
Use of event handling 6
Existance of a Static variable. 8
Float point variable comparison issue? 1
file [?] 7
XML serialize doesn't work 9

Top