Q:

C# program to demonstrate the example of a sealed class

0

C# program to demonstrate the example of a sealed class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the example of a sealed class in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

// Program to demonstrate the 
// example of a sealed class in C#.

using System;

sealed class MySealedClass
{
    public int num1;
    public int num2;

    public MySealedClass()
    {
        num1 = 500;
        num2 = 800;
    }
}

class SealedTest
{
    static void Main()
    {
        MySealedClass OB = new MySealedClass();
        
        Console.WriteLine(OB.num1);
        Console.WriteLine(OB.num2);
    }
}

Output:

500
800
Press any key to continue . . .

Explanation:

In the above program, we created a sealed class MySealedClass that contains two public data members initialized with 500 and 800 in the constructor of the same class.

We created one more class SealedTest that contains Main() method, in the Main() method we created object OB of MySealedClass and print the value of data members on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the example of unboxing... >>
<< Method returning object in C#...