-
-
Save tuannguyenssu/3ac8ad4d4929dbd2841e10f0ab19a098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Shape | |
{ | |
public virtual void PrintArea() | |
{ | |
} | |
} | |
public class Rectangle : Shape | |
{ | |
public int Height { get; set; } | |
public int Width { get; set; } | |
public virtual void SetHeight(int height) | |
{ | |
this.Height = height; | |
} | |
public virtual void SetWidth(int width) | |
{ | |
this.Width = width; | |
} | |
public override void PrintArea() | |
{ | |
Console.WriteLine(this.Height * this.Width); | |
} | |
} | |
public class Square : Shape | |
{ | |
public int Edge { get; set; } | |
public virtual void SetEdge(int edge) | |
{ | |
this.Edge = edge; | |
} | |
public override void PrintArea() | |
{ | |
Console.WriteLine(Math.Pow(this.Edge, 2)); | |
} | |
} | |
var rect = new Rectangle(); | |
rect.SetHeight(10); | |
rect.SetWidth(5); | |
System.Console.WriteLine(rect.PrintArea()); // Kết quả là 50 | |
var square = new Square(); | |
rect.SetEdge(10); | |
System.Console.WriteLine(rect.PrintArea()); // Kết quả là 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment