C# Program to Create a Sealed Class
Posted by Superadmin on August 14 2022 04:03:06

C# Program to Create a Sealed Class

 

 

This is a C# Program to create sealed class.

Problem Description

This C# Program Creates Sealed Class.

Problem Solution

Here sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as sealed class, this class cannot be inherited.

Program/Source Code

Here is source code of the C# Program to Create Sealed Class. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Create Sealed Class
 */
using System;
sealed class SealedClass
{
    public int x;
    public int y;
}
 
class SealedTest
{
    static void Main()
    {
        SealedClass sc = new SealedClass();
        sc.x = 100;
        sc.y = 180;
        Console.WriteLine("x = {0}, y = {1}", sc.x, sc.y);
        Console.ReadLine();
    }
}
Program Explanation

In this C# program, we have already defined the values of ‘x’ and ‘y’ variable as 100 and 180 respectively. The sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, this class cannot be inherited.

 
Runtime Test Cases
 
x = 100 ,y = 180