Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lesson8

136 views

Published on

Learn C#

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

Lesson8

  1. 1. Lesson 8 Learn C#. Series of C# lessons http://csharp.honcharuk.me/lesson-8
  2. 2. Agenda • Sealed • Abstract classes • Interfaces • Abstract Class versus Interface
  3. 3. Sealed • Sealed modifier prevents other classes from inheriting from it sealed class A { } //Gives an error, due to sealed class A class B : A { }
  4. 4. Abstract classes • Abstract class cannot be instantiated, and is frequently either partially implemented, or not at all implemented public abstract class Country { public string Name { get; set; } public string Currency { get; set; } public void PrintInformation() { Console.WriteLine(Name); Console.WriteLine(Currency); Console.WriteLine(this.GetFlagDescription()); } public abstract string GetFlagDescription(); }
  5. 5. Interfaces • An interface is not a class. • An interface is defined as a syntactical contract that all the classes inheriting the interface should follow. public interface IAlcohol { double AlcoholByVolume { get; set; } double GetMaximumAllowedWightForHuman(); }
  6. 6. Abstract Class versus Interface Feature Interface Abstract class Multiple inheritance YES NO Default implementation NO YES Access Modfiers NO (Everything goes public by default) YES Fields and Constants NO YES
  7. 7. Thank you! Questions?

×