CSharp examples for Custom Type:Inheritance
A class can inherit from another class.
using System;// ww w .j av a 2 s . c o m public class Item { public string Name; } public class Stock : Item // inherits from Item { public long SharesOwned; } public class Company : Item // inherits from Item { public decimal Mortgage; } class Test { static void Main(){ Stock msft = new Stock { Name="MSFT", SharesOwned=1000 }; Console.WriteLine (msft.Name); // MSFT Console.WriteLine (msft.SharesOwned); // 1000 Company mansion = new Company { Name="Mansion", Mortgage=250000 }; Console.WriteLine (mansion.Name); // Mansion Console.WriteLine (mansion.Mortgage); // 250000 } }