c# - How do I limit overriding in a hierarchy? -
This is an example, I am curious to know how to get this.
I want to enable only sub sections of animals
, they should be able to determine the number of those feet, but I still able to set them their own color Therefore, I want to limit the classes to more than the square since it changes the Legs
property.
Public intangible class animal {public string color {get; Protected Set; } Receive public int foot { Protected Set; } Speak the public essence string (); } Public square dog: Animal {public dog} (foot = 4;} public override string Speak (return) "Woof";} Public Sealed Class Springer: Dogs {public springer} {color = "lever and white"; } Public Sealed Class Chihuahua: Dogs {Public Chihuahua () {color = "white";} Public override string speak (return) "return" * annoying * YAP! "For example, I want to end such subclasses. I: abstract Public sealed class dalmatian: dog {public dalmatian () {feet = 20; color = "black and white";}}
How can it be obtained?
< P> I know that I can stop overriding sub-classes by sealing the implementation of a function in parent class. I tried with foot
property but I can not get it to work Thanks
Z rather than in the field of abstract class, you must create a property (delete setter), and in essence it.
In Animals
Get the Public Essence In Legs; }
In dog
public override seal int foot {get {return 4; }}
Comments
Post a Comment