C# Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 373 Page Views: 

Is there any way tp prevent a class being inherited , so that it can't act as a base class to some other class?



Posted By: Avi Date: 1 October 2010 11:37:31 AM
 Answer:

Yes, it is possible. This can be done with the help of the sealed keyword. It can be done as follows:- sealed class sum { public int x; public int y; } So whenevr anyone tries to inherit this class an message will be displayed as:- "cannot inherit from Sealed class"


Posted By: avibtech


Date: 1 October 2010 11:37:31 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image f1itL9
Related Questions
C# : Will this code compile: public static const int A = 10;

Will this code compile: public static const int A = 10;

No, const cannot be static
Category: C# Date: 10/13/2010 4:19:46 PM
C# : What will be the output of code:
int x = 0;
do
{
Console.Write(x++);
} while(x<5);
C# : What is Graphics object and how do you use it?

What is Graphics object and how do you use it?

Graphics class encapsulates GDI+ drawing surface. Grp.DrawLine(new Pen(Color.Black, 3), 10.0, 50, 34....
Category: C# Date: 10/13/2010 3:26:47 PM
C# : How do you define class that uses generic type?

How do you define class that uses generic type?

class Name<T> {}
Category: C# Date: 10/13/2010 3:10:32 PM
C# : How do you access base class methods in derived class?

How do you access base class methods in derived class?

using base keyword
Category: C# Date: 10/13/2010 2:47:14 PM