.


:




:

































 

 

 

 


Who() Derivedl




Derived3 Derived2, Derivedl, , , Base. , Who (), Derivedl, , Derived3 Derived2, Who () , Derivedl.

: virtual override. .

C# . - , , , . C# : .

, , . , . , . , , , .

, TwoDShape. , TwoDShape, Area (). , -, Area () TwoDShape , . . TwoDShape.

// -.

Using System;

class TwoDShape { double pri_width; double pri_height;

// , public TwoDShape() {

Width = Height = 0.0; name = "null";

}

// .'

public TwoDShape(double w, double h, string n) {

Width = w;

Height = h; name = n;

}

// , public TwoDShape(double , string n) {

Width = Height = x; name = n;

}

// TwoDShape. public TwoDShape(TwoDShape ob) {

Width = ob.Width;

Height = ob.Height; name = ob.name;

}

// , public double Width {

get { return pri_width; }

set { pri_width = value < 0? -value: value; }

}

public double Height {

get { return pri_height; }

set -{ pri_height = value < 0? -value: value; }

}

public string name { get; set; }

public void ShowDim() {

Console.WriteLine(" " +

Width + " " + Height);

}

public virtual double Area() {

Console.WriteLine(" Area() "); return 0.0;

}

}

// , TwoDShape.

class Triangle: TwoDShape { string Style;

// , , public Triangle() {

Style = "null";

}

// Triangle, public Triangle(string s, double w, double h): base (w, h, "") {

Style = s;

}

// , public Triangle(double x): base(x, "") {

Style = "";

}

// Triangle, public Triangle(Triangle ob): base(ob) {

Style = ob.Style;

}

// Area() Triangle, public override double Area() { return Width * Height / 2;

}

// , public void ShowStyle() {

Console.WriteLine(" " + Style);

}

I/ , TwoDShape. class Rectangle: TwoDShape {

// Rectangle, public Rectangle(double w, double h): base (w, h, "") { }

// , public Rectangle(double x): base(x, "") { }

// Rectangle, public Rectangle(Rectangle ob): base(ob) { }

// true, // , public bool IsSquareO {

if(Width == Height) return true; return false;

}

// Area() Rectangle, public override double Area() { return Width * Height;

}

}

class DynShapes {

static void Main() {

TwoDShape[] shapes = new TwoDShape[5];

shapes[0] = new Triangle("", 8.0, 12.0); shapes[1] = new Rectangle(10);

shapes[2] = new Rectangle(10, 4);

shapes[3] = new Triangle(7.0);

shapes[4] = new TwoDShape(10, 20, " ");

for (int i=0; i < shapes.Length; i++) {

Console.WriteLine(" " + shapes[i].name);

Console.WriteLine(" " + shapes[i].Area());

Console.WriteLine();

}

}

}





:


: 2016-12-03; !; : 524 |


:

:

.
==> ...

1974 - | 1855 -


© 2015-2024 lektsii.org - -

: 0.016 .