Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
4. Inheritance
//4. Inheritance using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Inheritance is defining new types based on existing ones //New type is also the type it has inherited from var apple = new Apple(); apple.EatMe(); Console.WriteLine(apple.GetMyName()); Console.WriteLine((apple as Fruit).GetMyName()); Console.WriteLine(apple is Fruit); } } public class Fruit { public void EatMe() { Console.WriteLine("Eating..."); } public virtual string GetMyName() { return "Some fruit"; } } public class Apple: Fruit //Inherit from Fruit. Now Apple is a Fruit too. { public override string GetMyName() { return "Apple"; } } }
run
|
edit
|
history
|
help
0
ss
CommandForce3
HTML Hex to RGB without using System.Drawing C#
code
Time diff with date list
Timer2
Error
Interface
a6
codetility CyclicRotation