Sealed methods : Sealed : Class C# Examples


C# Examples » Class » Sealed »

 

Sealed methods









    
using  System;

public  class  BaseClass
{
    public  string  lastName;
    public  string  firstName;

    public  BaseClass(string  lastName,  string  firstName)
    {
        this.lastName  =  lastName;
        this.firstName  =  firstName;
    }

    public  virtual  void  Accelerate()
    {
        Console.WriteLine("In  BaseClass  Accelerate()  method");
        Console.WriteLine(firstName  +  "  accelerating");
    }

}

public  class  DerivedClass  :  BaseClass
{
    public  DerivedClass(string  lastName,  string  firstName)  :  base(lastName,  firstName)
    {
    }

    sealed  public  override  void  Accelerate()
    {
        Console.WriteLine("In  DerivedClass  Accelerate()  method");
        Console.WriteLine(firstName  +  "  accelerating");
    }

}

class  MainClass
{

    public  static  void  Main()
    {
        DerivedClass  myDerivedClass  =  new  DerivedClass("A",  "M");

        Console.WriteLine("Calling  myDerivedClass.Accelerate()");
        myDerivedClass.Accelerate();
    }
}
    
   
  
   



Output

Calling myDerivedClass.Accelerate()
In DerivedClass Accelerate() method
M accelerating


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Sealed