A sealed property overrides a property in a base class, but itself cannot be overridden further in any derived class. Is it true?

Locked A sealed property overrides a property in a base class, but itself cannot be overridden further in any derived class. Is it true?

  • 03 Maret 2012 12:44
     
     

    Hi Friends,

    In an unauthetic study material about C# I found the statement as mentioned in subject is it true?

Semua Balasan

  • 03 Maret 2012 13:36
     
     Jawab
  • 03 Maret 2012 14:05
     
     Jawab

    Yes. Actually the statement should be :

    "A sealed property can overridea property in a base class, but itself cannot be overridden further in any derived class"


    Please mark this post as answer if it solved your problem. Happy Programming!

  • 03 Maret 2012 19:25
     
     Jawab

    True, the simple statement "a sealed property cannot be overriden" should be sufficient, it doesn't imply a sealed property cannot override an other.

    Dorian

  • 04 Maret 2012 13:20
     
     Jawab Memiliki Kode

    Hi Ajay,

    Please see this below sample:

    class One
        {
            protected virtual void F() { Console.WriteLine("One.F"); }
            protected virtual void F2() { Console.WriteLine("One.F2"); }
        }
        class Two : One
        {
            sealed protected override void F() { Console.WriteLine("Two.F"); }
            protected override void F2() { Console.WriteLine("One.F3"); }
        }
        class Three : Two
        {
            // Attempting to override F causes compiler error CS0239.
            // protected override void F() { Console.WriteLine("Three.F"); }
    
            // Overriding F2 is allowed.
            protected override void F2() { Console.WriteLine("Three.F2"); }
        }


    Regards, http://shwetamannjain.blogspot.com

  • 05 Maret 2012 16:12
     
     Jawab
    Actually, a sealed property must override an inherited property. If it doesn't override anything, you don't need to seal it.