t2:
8 12 48
Triangle:
public Triangle(Triangle ob): base(ob) {
Style = ob.Style;
}
Triangle ( base) TwoDShape.
public TwoDShape(TwoDShape ob) {
Width = ob.Width;
Height = ob.Height;
}
, TwoDShape () TwoDShape, Triangle () Triangle. , , . , TwoDShape () , TwoDShape. TwoDShape () , TwoDShape, , , .
, virtual . , . ,
. , , . C# , , , , . . , , . , , .
virtual, . , override. . , , , . , static abstract ( ).
C# : , , . , C# .
|
|
, .
// .
Using System;
class Base {
// , public virtual void Who() {
Console.WriteLine(" Who() Base");
}
}
class Derivedl: Base {
// Who() , public override void Who() {
Console.WriteLine(" Who() Derivedl");
}
}
class Derived2: Base {
// Who() , public override void Who() {
Console.WriteLine(" Who() Derived2");
class OverrideDemo { static void Main() {
Base baseOb = new Base();
Derivedl dObl = new DerivedlO;
Deri'ved2 dOb2 = new Derived2();
Base baseRef; //
baseRef = baseOb; baseRef.Who();
baseRef = dObl; baseRef.Who();
baseRef = d0b2; baseRef.Who();
}
}