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
- Ditandai sebagai Jawaban oleh Bob ShenMicrosoft Contingent Staff, Moderator 15 Maret 2012 2:29
-
03 Maret 2012 14:05
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!
- Ditandai sebagai Jawaban oleh Bob ShenMicrosoft Contingent Staff, Moderator 15 Maret 2012 2:29
-
03 Maret 2012 19:25
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
- Disarankan sebagai Jawaban oleh DorianCoromptMicrosoft Employee 03 Maret 2012 19:25
- Ditandai sebagai Jawaban oleh Bob ShenMicrosoft Contingent Staff, Moderator 15 Maret 2012 2:29
-
04 Maret 2012 13:20
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
- Disarankan sebagai Jawaban oleh Shweta Jain 04 Maret 2012 13:20
- Ditandai sebagai Jawaban oleh Bob ShenMicrosoft Contingent Staff, Moderator 15 Maret 2012 2:29
-
05 Maret 2012 16:12
Actually, a sealed property must override an inherited property. If it doesn't override anything, you don't need to seal it.- Ditandai sebagai Jawaban oleh Bob ShenMicrosoft Contingent Staff, Moderator 15 Maret 2012 2:29