//C# Inheritance ( Overerving ) - Inherits Object Oriented Programming public class Person { private string m_Name; public virtual string Name { get { Name = this.m_Name; } set { this.m_Name = value; } } } public class Student : Person { private string m_ClassGroup; public virtual string ClassGroup { get { ClassGroup = this.m_ClassGroup; } set { this.m_ClassGroup = ClassGroup; } } } public class Client1 { void Main() { Person person1 = new Person(); person1.Name = "John"; Console.WriteLine(person1.Name); Student student1 = new Student(); student1.Name = "Jane"; Console.WriteLine(student1.Name); student1.ClassGroup = "Group 1"; Console.WriteLine(student1.ClassGroup); Console.ReadLine(); } } public class Teacher : Person { private string m_Course; public virtual string Course { get { Course = this.m_Course; } set { this.m_Course = value; } } } public class Counter { protected int m_Value; public virtual void GetValue() { GetValue = this.m_Value; } public virtual void Raise() { this.m_Value += new System.EventHandler(1); } public virtual void Lower() { this.m_Value = 1; } } public class SettableCounter : Counter { public virtual void SetValue(int value) { m_Value = value; } } public class Client2 { void Main() { Counter counter1 = new Counter(); Console.WriteLine((GetValue() == 0)); Raise(); Console.WriteLine((GetValue() == 1)); Lower(); Console.WriteLine((GetValue() == 0)); SettableCounter specialCounter1 = new SettableCounter(); Console.WriteLine((GetValue() == 0)); SetValue(10); Console.WriteLine((GetValue() == 10)); Raise(); Console.WriteLine((GetValue() == 11)); Lower(); Console.WriteLine((GetValue() == 10)); Console.ReadLine(); } } public class Address { private string m_Street; private string m_Number; private string m_ZipCode; private string m_City; public virtual string Street { get { Street = this.m_Street; } set { this.m_Street = value; } } public virtual string Number { get { Number = this.m_Number; } set { this.m_Number = value; } } public virtual string ZipCode { get { ZipCode = this.m_ZipCode; } set { this.m_ZipCode = value; } } public virtual string City { get { City = this.m_City; } set { this.m_City = value; } } } public class Employee { private string m_Name; private Address m_Address; public virtual string Name { get { Name = this.m_Name; } set { this.m_Name = value; } } public virtual Address Address { get { Address = this.m_Address; } set { this.m_Address = value; } } } public class Manager : Employee { private Car m_Car; public virtual Car Car { get { Car = this.m_Car; } set { this.m_Car = value; } } } public class Car { private string m_Brand; public virtual string Brand { get { Brand = this.m_Brand; } set { this.m_Brand = value; } } } public class Exercise2Solution { void Main() { Republic france = new Republic(); france.Capital = "Paris"; france.President = "Sarkozy"; Monarchy unitedKingdom = new Monarchy(); unitedKingdom.Capital = "London"; unitedKingdom.Monarch = "Elizabeth"; } } public class Country { private string m_Capital; public virtual string Capital { get { Capital = this.m_Capital; } set { this.m_Capital = value; } } } public class Monarchy : Country { private string m_Monarch; public virtual string Monarch { get { Monarch = this.m_Monarch; } set { this.m_Monarch = value; } } } public class Republic : Country { private string m_President; public virtual string President { get { President = this.m_President; } set { this.m_President = value; } } } //Bezoek www.vbvoorbeelden.be voor meer C# voorbeelden. //Copyright - De Wolf / vbvoorbeelden - 2003-2010 - Alle rechten voorbehouden.