repl.it
@kenanhancer/

PolymorphismDemo8

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;

class MainClass {
  public static void Main (string[] args) {
    Bike bike1 = new Splendor(); // Upcasting
    bike1.run();
  }
}

class Bike
{
  public virtual void run()
  {
    Console.WriteLine("running");
  }
}

class Splendor : Bike
{
  public override void run()
  {
    Console.WriteLine("running safely with 60km");
  }
}
?