Difference between revisions of "Polymorphism"
From Logic Wiki
m (1 revision imported) |
(public int Width{get; set;}) |
||
| Line 18: | Line 18: | ||
this.hiz += 2 * ivme; | this.hiz += 2 * ivme; | ||
} | } | ||
| + | ------------------- | ||
| + | <pre class=brush:csharp;"> | ||
| + | public class Circle : Shape | ||
| + | { | ||
| + | } | ||
| + | |||
| + | public class Rectangle : Shape | ||
| + | { | ||
| + | } | ||
| + | |||
| + | public class Shape | ||
| + | { | ||
| + | |||
| + | } | ||
Revision as of 09:56, 13 June 2017
if you want to use a method or property of a base class differently in child classes you need polymorphism.
Simply add virtual keyword to base class's method
public virtual void Gazla(int ivme)
{
this.Hiz += ivme;
}
in child class
public override void Gazla(int icme)
{
// base.Gazla // to use base method as it is
this.hiz += 2 * ivme;
}
public class Circle : Shape
{
}
public class Rectangle : Shape
{
}
public class Shape
{
}