top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How in .net we can prevent a class from being inherited?

+1 vote
283 views
How in .net we can prevent a class from being inherited?
posted Aug 3, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Not an expert but try the sealed keyword to prohibit a class from being inherited. Let me know if it does not work.

answer Aug 3, 2014 by Salil Agrawal
Similar Questions
+3 votes

By-default all the methods & variables in class are private.

In C#.net Main() method is private then how compiler access this Main() Method out side the class because compiler is not part of our program then how compiler access this Main() method?

Here we loose our data abstraction property ? Can anyone put some light on it?

+4 votes

Why can’t we use a static class instead of singleton?

+1 vote
using System;

namespace CareerRideTest
{    
  class A
  {    
    public A()
    {
      Console.WriteLine("I am in A");
    }
  }

  class B : A
  {
    public B()
    {
      Console.WriteLine("I am in B");
    }
  }

  class C : B
  {
    static C()
    {
      Console.WriteLine("I am in Static C");
    }
    public C()
    {
      Console.WriteLine("I am in C");
    }
  }    

  class MainClass
  {
    static void Main(string[] args)
    {
      C obj = new C();    
      Console.ReadKey();    
    }
  }    
}
...