What is Static classes?

What is Static classes?

Static Class:-These are simply declared using the static modifier. They cannot be derived from or instantiated, and they have no constructors .
Their members must all be static.
Example:-
using System;

public static class staticexample
{
    public static void Foo()
    {
        Console.WriteLine ("Hello");
    }
    
    }

// Uncommenting this creates a compile-time error,
// as static classes can't be derived from
// public class DerivationAttempt :staticexample{}

class Test
{
    static void Main()
    {
        staticexample.Foo();
    }
}

By:kamal
Date:2012-10-10 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Links

C interview questions and answers for experienced and fresher