using System; public class Camera { public string Company; public string Model; public Camera(string Company, string Model) { this.Company = Company; this.Model = Model; } public virtual void PhotoEdit() { Console.WriteLine(Model + " editing the photos!"); } } public class DSLR : Camera { public DSLR(string Company, string Model) : base(Company, Model) { } public override void PhotoEdit() { Console.WriteLine("Pushing gas pedal of " + Model); base.PhotoEdit(); } } public class SLR : Camera { public SLR(string Company, string Model) : base(Company, Model) { } public override void PhotoEdit() { Console.WriteLine("Using the software of " + Model); base.PhotoEdit(); } } class abcabc { public static void Main() { DSLR myDSLR = new DSLR("Canon", "PowerShot110"); myDSLR.PhotoEdit(); SLR mySLR = new SLR("Nikon", "Mark III"); mySLR.PhotoEdit(); } }
Monday, 30 April 2012
Polymorphism in C# ( Camera Example )
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment