Search This Blog

Saturday, July 9, 2011

Sealed class

Sealed class

  1. It is complete class
  2. It is allow creating an object
  3. It is also called instance class
  4. Inheritance is not possible for Sealed Class. Means No one can be able to inherit from a Sealed Class but sealed class can inherit from any other class (The Parent Class should not be Sealed Class).
  5. Sealed class can never acts as a Parent Class
  6. Static class is by default sealed class only.

Example for Sealed Class:

----------------------------------------------------

­­­­public sealed class ToyCalc

{

}

public class AdvancedToyCalc : ToyCalc

{

}

Note 1: The above Code is wrong since a sealed class can never act as a Base or Parent Class.

Note 2: But ToyCalc class can inherit from other classes ex.

Ex: ­­­­public sealed class ToyCalc: Toy

The Toy Class should not be a Static Class or SealedClass.

No comments: