sealed class Test { public int Number; public string Name; } |
Public sealed class Test { public int Number; public string Name; } |
Here we can declare a class that is derived from another class can also be sealed. Check below example
Public sealed class Test { public int Number; public string Name; } |
Public sealed class child1:Test { public string Name; } |
using System; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Irregular tri = new Irregular(42.73, 35.05); tri.Describe("Irregular"); } } public abstract class Triangle { private double bs; private double hgt; public Triangle(double length , double height) { bs = length; hgt = height; } public virtual double Area() { return bs * hgt / 2; } public void Describe(string type) { Console.WriteLine("Triangle - {0}", type); Console.WriteLine("Base: {0}", bs); Console.WriteLine("Height: {0}", hgt); Console.WriteLine("Area: {0}", Area()); } } sealed public class Irregular : Triangle { public Irregular(double Base, double Height): base(Base, Height) { } } } |
From above example we can easily say that sealed classes can’t inherit or acquire properties from parent class.
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
7 comments :
Nice .. Article
Public sealed class Test
{
public int Number;
public string Name;
}
Public sealed class child1:Test
{
public string Name;
}
Will the above code work ? since test class is already sealed class.
????????
above code does not work, as class Test is already marked as sealed
I like this article... But what is the use of access specifier using before sealed class
its not work
Nice article keep it up.
Suresh one dout what is the difference between web application and windows application plz tell me.......