<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FClass_Interface%2FClass_Inheritance</id>
		<title>Csharp/C Sharp/Class Interface/Class Inheritance - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FClass_Interface%2FClass_Inheritance"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Inheritance&amp;action=history"/>
		<updated>2026-04-29T16:34:11Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Inheritance&amp;diff=616&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Inheritance&amp;diff=616&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Inheritance&amp;diff=617&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Inheritance&amp;diff=617&amp;oldid=prev"/>
				<updated>2010-05-26T11:39:11Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A base class reference can refer to a derived class object==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// A base class reference can refer to a derived class object. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class X { &lt;br /&gt;
  public int a; &lt;br /&gt;
 &lt;br /&gt;
  public X(int i) { &lt;br /&gt;
    a = i; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class Y : X { &lt;br /&gt;
  public int b; &lt;br /&gt;
 &lt;br /&gt;
  public Y(int i, int j) : base(j) { &lt;br /&gt;
    b = i; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class BaseRef { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    X x = new X(10); &lt;br /&gt;
    X x2;  &lt;br /&gt;
    Y y = new Y(5, 6); &lt;br /&gt;
 &lt;br /&gt;
    x2 = x; // OK, both of same type &lt;br /&gt;
    Console.WriteLine(&amp;quot;x2.a: &amp;quot; + x2.a); &lt;br /&gt;
 &lt;br /&gt;
    x2 = y; // still Ok because Y is derived from X &lt;br /&gt;
    Console.WriteLine(&amp;quot;x2.a: &amp;quot; + x2.a); &lt;br /&gt;
 &lt;br /&gt;
    // X references know only about X members &lt;br /&gt;
    x2.a = 19; // OK &lt;br /&gt;
//    x2.b = 27; // Error, X doesn&amp;quot;t have a b member &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==a multilevel hierarchy==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/*  In a multilevel hierarchy, the  &lt;br /&gt;
    first override of a virtual method &lt;br /&gt;
    that is found while moving up the &lt;br /&gt;
    heirarchy is the one executed. */ &lt;br /&gt;
  &lt;br /&gt;
using System;  &lt;br /&gt;
  &lt;br /&gt;
class Base {  &lt;br /&gt;
  // Create virtual method in the base class.   &lt;br /&gt;
  public virtual void who() {  &lt;br /&gt;
    Console.WriteLine(&amp;quot;who() in Base&amp;quot;);  &lt;br /&gt;
  }  &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
class Derived1 : Base {  &lt;br /&gt;
  // Override who() in a derived class.  &lt;br /&gt;
  public override void who() {  &lt;br /&gt;
    Console.WriteLine(&amp;quot;who() in Derived1&amp;quot;);  &lt;br /&gt;
  }  &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
class Derived2 : Derived1 {  &lt;br /&gt;
  // This class also does not override who().  &lt;br /&gt;
}  &lt;br /&gt;
 &lt;br /&gt;
class Derived3 : Derived2 {  &lt;br /&gt;
  // This class does not override who().  &lt;br /&gt;
}  &lt;br /&gt;
 &lt;br /&gt;
public class NoOverrideDemo2 {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    Derived3 dOb = new Derived3();  &lt;br /&gt;
    Base baseRef; // a base-class reference  &lt;br /&gt;
  &lt;br /&gt;
    baseRef = dOb;   &lt;br /&gt;
    baseRef.who(); // calls Derived1&amp;quot;s who()  &lt;br /&gt;
  }  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A multilevel hierarchy 1==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// A multilevel hierarchy. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class TwoDShape { &lt;br /&gt;
  double pri_width;  // private &lt;br /&gt;
  double pri_height; // private  &lt;br /&gt;
 &lt;br /&gt;
  // Default constructor. &lt;br /&gt;
  public TwoDShape() { &lt;br /&gt;
    width = height = 0.0; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor for TwoDShape. &lt;br /&gt;
  public TwoDShape(double w, double h) { &lt;br /&gt;
    width = w; &lt;br /&gt;
    height = h; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct object with equal width and height. &lt;br /&gt;
  public TwoDShape(double x) { &lt;br /&gt;
    width = height = x; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Properties for width and height. &lt;br /&gt;
  public double width { &lt;br /&gt;
     get { return pri_width; } &lt;br /&gt;
     set { pri_width = value; } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public double height { &lt;br /&gt;
     get { return pri_height; } &lt;br /&gt;
     set { pri_height = value; } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void showDim() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Width and height are &amp;quot; + &lt;br /&gt;
                       width + &amp;quot; and &amp;quot; + height); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// A derived class of TwoDShape for triangles. &lt;br /&gt;
class Triangle : TwoDShape { &lt;br /&gt;
  string style; // private &lt;br /&gt;
   &lt;br /&gt;
  /* A default constructor. This invokes the default &lt;br /&gt;
     constructor of TwoDShape. */ &lt;br /&gt;
  public Triangle() { &lt;br /&gt;
    style = &amp;quot;null&amp;quot;; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor &lt;br /&gt;
  public Triangle(string s, double w, double h) : base(w, h) { &lt;br /&gt;
    style = s;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct an isosceles triangle. &lt;br /&gt;
  public Triangle(double x) : base(x) { &lt;br /&gt;
    style = &amp;quot;isosceles&amp;quot;;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Return area of triangle. &lt;br /&gt;
  public double area() { &lt;br /&gt;
    return width * height / 2; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Display a triangle&amp;quot;s style. &lt;br /&gt;
  public void showStyle() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Triangle is &amp;quot; + style); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Extend Triangle. &lt;br /&gt;
class ColorTriangle : Triangle { &lt;br /&gt;
  string color; &lt;br /&gt;
 &lt;br /&gt;
  public ColorTriangle(string c, string s, &lt;br /&gt;
                       double w, double h) : base(s, w, h) { &lt;br /&gt;
    color = c; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Display the color. &lt;br /&gt;
  public void showColor() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Color is &amp;quot; + color); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class Shapes6 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    ColorTriangle t1 =  &lt;br /&gt;
         new ColorTriangle(&amp;quot;Blue&amp;quot;, &amp;quot;right&amp;quot;, 8.0, 12.0); &lt;br /&gt;
    ColorTriangle t2 =  &lt;br /&gt;
         new ColorTriangle(&amp;quot;Red&amp;quot;, &amp;quot;isosceles&amp;quot;, 2.0, 2.0); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t1: &amp;quot;); &lt;br /&gt;
    t1.showStyle(); &lt;br /&gt;
    t1.showDim(); &lt;br /&gt;
    t1.showColor(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t1.area()); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t2: &amp;quot;); &lt;br /&gt;
    t2.showStyle(); &lt;br /&gt;
    t2.showDim(); &lt;br /&gt;
    t2.showColor(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t2.area()); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==An example of inheritance-related name hiding==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// An example of inheritance-related name hiding. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class A { &lt;br /&gt;
  public int i = 0; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Create a derived class. &lt;br /&gt;
class B : A { &lt;br /&gt;
  new int i; // this i hides the i in A &lt;br /&gt;
 &lt;br /&gt;
  public B(int b) { &lt;br /&gt;
    i = b; // i in B &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void show() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;i in derived class: &amp;quot; + i); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class NameHiding { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    B ob = new B(2); &lt;br /&gt;
 &lt;br /&gt;
    ob.show(); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A simple class hierarchy==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// A simple class hierarchy. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
public class Shapes { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Triangle t1 = new Triangle(); &lt;br /&gt;
    Triangle t2 = new Triangle(); &lt;br /&gt;
 &lt;br /&gt;
    t1.width = 4.0; &lt;br /&gt;
    t1.height = 4.0; &lt;br /&gt;
    t1.style = &amp;quot;isosceles&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
    t2.width = 8.0; &lt;br /&gt;
    t2.height = 12.0; &lt;br /&gt;
    t2.style = &amp;quot;right&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t1: &amp;quot;); &lt;br /&gt;
    t1.showStyle(); &lt;br /&gt;
    t1.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t1.area()); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t2: &amp;quot;); &lt;br /&gt;
    t2.showStyle(); &lt;br /&gt;
    t2.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t2.area()); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
// A class for two-dimensional objects. &lt;br /&gt;
public class TwoDShape { &lt;br /&gt;
  public double width; &lt;br /&gt;
  public double height; &lt;br /&gt;
 &lt;br /&gt;
  public void showDim() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Width and height are &amp;quot; + &lt;br /&gt;
                       width + &amp;quot; and &amp;quot; + height); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Triangle is derived from TwoDShape. &lt;br /&gt;
public class Triangle : TwoDShape { &lt;br /&gt;
  public string style; // style of triangle &lt;br /&gt;
   &lt;br /&gt;
  // Return area of triangle. &lt;br /&gt;
  public double area() { &lt;br /&gt;
    return width * height / 2; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Display a triangle&amp;quot;s style. &lt;br /&gt;
  public void showStyle() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Triangle is &amp;quot; + style); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Build a derived class of Vehicle for trucks==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# A Beginner&amp;quot;s Guide&lt;br /&gt;
By Schildt&lt;br /&gt;
Publisher: Osborne McGraw-Hill&lt;br /&gt;
ISBN: 0072133295&lt;br /&gt;
*/&lt;br /&gt;
/* &lt;br /&gt;
  Project 8-1 &lt;br /&gt;
 &lt;br /&gt;
  Build a derived class of Vehicle for trucks. &lt;br /&gt;
*/ &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class Vehicle {    &lt;br /&gt;
  int pri_passengers; // number of passengers    &lt;br /&gt;
  int pri_fuelcap;    // fuel capacity in gallons   &lt;br /&gt;
  int pri_mpg;        // fuel consumption in miles per gallon   &lt;br /&gt;
   &lt;br /&gt;
  // This is a constructor for Vehicle.  &lt;br /&gt;
  public Vehicle(int p, int f, int m) {  &lt;br /&gt;
    passengers = p;  &lt;br /&gt;
    fuelcap = f;  &lt;br /&gt;
    mpg = m;  &lt;br /&gt;
  }  &lt;br /&gt;
 &lt;br /&gt;
  // Return the range.   &lt;br /&gt;
  public int range() {   &lt;br /&gt;
    return mpg * fuelcap;   &lt;br /&gt;
  }   &lt;br /&gt;
   &lt;br /&gt;
  // Compute fuel needed for a given distance.  &lt;br /&gt;
  public double fuelneeded(int miles) {   &lt;br /&gt;
    return (double) miles / mpg;   &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Properties &lt;br /&gt;
  public int passengers { &lt;br /&gt;
    get { return pri_passengers; } &lt;br /&gt;
    set { pri_passengers = value; } &lt;br /&gt;
  }   &lt;br /&gt;
 &lt;br /&gt;
  public int fuelcap { &lt;br /&gt;
    get { return pri_fuelcap; } &lt;br /&gt;
    set { pri_fuelcap = value; } &lt;br /&gt;
  }   &lt;br /&gt;
 &lt;br /&gt;
  public int mpg { &lt;br /&gt;
    get { return pri_mpg; } &lt;br /&gt;
    set { pri_mpg = value; } &lt;br /&gt;
  }   &lt;br /&gt;
}    &lt;br /&gt;
  &lt;br /&gt;
// Use Vehicle to create a Truck specialization.    &lt;br /&gt;
class Truck : Vehicle {  &lt;br /&gt;
  int pri_cargocap; // cargo capacity in pounds  &lt;br /&gt;
  &lt;br /&gt;
  // This is a constructor for Truck.  &lt;br /&gt;
  public Truck(int p, int f, int m, int c) : base(p, f, m)  &lt;br /&gt;
  {  &lt;br /&gt;
    cargocap = c;  &lt;br /&gt;
  }  &lt;br /&gt;
 &lt;br /&gt;
  // Property for cargocap. &lt;br /&gt;
  public int cargocap { &lt;br /&gt;
    get { return pri_cargocap; } &lt;br /&gt;
    set { pri_cargocap = value; } &lt;br /&gt;
  }   &lt;br /&gt;
}  &lt;br /&gt;
    &lt;br /&gt;
public class TruckDemo {    &lt;br /&gt;
  public static void Main() {    &lt;br /&gt;
  &lt;br /&gt;
    // construct some trucks &lt;br /&gt;
    Truck semi = new Truck(2, 200, 7, 44000);    &lt;br /&gt;
    Truck pickup = new Truck(3, 28, 15, 2000);    &lt;br /&gt;
    double gallons;   &lt;br /&gt;
    int dist = 252;   &lt;br /&gt;
   &lt;br /&gt;
    gallons = semi.fuelneeded(dist);    &lt;br /&gt;
    &lt;br /&gt;
    Console.WriteLine(&amp;quot;Semi can carry &amp;quot; + semi.cargocap +  &lt;br /&gt;
                       &amp;quot; pounds.&amp;quot;); &lt;br /&gt;
    Console.WriteLine(&amp;quot;To go &amp;quot; + dist + &amp;quot; miles semi needs &amp;quot; +   &lt;br /&gt;
                       gallons + &amp;quot; gallons of fuel.\n&amp;quot;);   &lt;br /&gt;
       &lt;br /&gt;
    gallons = pickup.fuelneeded(dist);    &lt;br /&gt;
    &lt;br /&gt;
    Console.WriteLine(&amp;quot;Pickup can carry &amp;quot; + pickup.cargocap +  &lt;br /&gt;
                       &amp;quot; pounds.&amp;quot;); &lt;br /&gt;
    Console.WriteLine(&amp;quot;To go &amp;quot; + dist + &amp;quot; miles pickup needs &amp;quot; +   &lt;br /&gt;
                       gallons + &amp;quot; gallons of fuel.&amp;quot;);  &lt;br /&gt;
  }    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Call a hidden method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Call a hidden method. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class A { &lt;br /&gt;
  public int i = 0; &lt;br /&gt;
 &lt;br /&gt;
  // show() in A &lt;br /&gt;
  public void show() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;i in base class: &amp;quot; + i); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Create a derived class. &lt;br /&gt;
class B : A { &lt;br /&gt;
  new int i; // this i hides the i in A &lt;br /&gt;
 &lt;br /&gt;
  public B(int a, int b) { &lt;br /&gt;
    base.i = a; // this uncovers the i in A &lt;br /&gt;
    i = b; // i in B &lt;br /&gt;
  } &lt;br /&gt;
  // This hides show() in A. Notice the use of new. &lt;br /&gt;
  new public void show() { &lt;br /&gt;
    base.show(); // this calls show() in A &lt;br /&gt;
 &lt;br /&gt;
    // this displays the i in B &lt;br /&gt;
    Console.WriteLine(&amp;quot;i in derived class: &amp;quot; + i); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class UncoverName123 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    B ob = new B(1, 2); &lt;br /&gt;
 &lt;br /&gt;
    ob.show(); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Hierarchy test==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Learning C# &lt;br /&gt;
by Jesse Liberty&lt;br /&gt;
Publisher: O&amp;quot;Reilly &lt;br /&gt;
ISBN: 0596003765&lt;br /&gt;
*/&lt;br /&gt;
 using System;&lt;br /&gt;
 class Window&lt;br /&gt;
 {&lt;br /&gt;
     // constructor takes two integers to&lt;br /&gt;
     // fix location on the console&lt;br /&gt;
     public Window(int top, int left)&lt;br /&gt;
     {&lt;br /&gt;
         this.top = top;&lt;br /&gt;
         this.left = left;&lt;br /&gt;
     }&lt;br /&gt;
     // simulates drawing the window&lt;br /&gt;
     public void DrawWindow()&lt;br /&gt;
     {&lt;br /&gt;
         Console.WriteLine(&amp;quot;Drawing Window at {0}, {1}&amp;quot;,&lt;br /&gt;
             top, left);&lt;br /&gt;
     }&lt;br /&gt;
     // these members are private and thus invisible&lt;br /&gt;
     // to derived class methods; we&amp;quot;ll examine this&lt;br /&gt;
     // later in the chapter&lt;br /&gt;
     private int top;&lt;br /&gt;
     private int left;&lt;br /&gt;
 }&lt;br /&gt;
 // ListBox derives from Window&lt;br /&gt;
 class ListBox : Window&lt;br /&gt;
 {&lt;br /&gt;
     // constructor adds a parameter&lt;br /&gt;
     public ListBox(&lt;br /&gt;
         int top,&lt;br /&gt;
         int left,&lt;br /&gt;
         string theContents):&lt;br /&gt;
         base(top, left)  // call base constructor&lt;br /&gt;
     {&lt;br /&gt;
         mListBoxContents = theContents;&lt;br /&gt;
     }&lt;br /&gt;
     // a new version (note keyword) because in the&lt;br /&gt;
     // derived method we change the behavior&lt;br /&gt;
     public new void DrawWindow()&lt;br /&gt;
     {&lt;br /&gt;
         base.DrawWindow();  // invoke the base method&lt;br /&gt;
         Console.WriteLine (&amp;quot;Writing string to the listbox: {0}&amp;quot;,&lt;br /&gt;
             mListBoxContents);&lt;br /&gt;
     }&lt;br /&gt;
     private string mListBoxContents;  // new member variable&lt;br /&gt;
 }&lt;br /&gt;
 public class HierarchyTester&lt;br /&gt;
 {&lt;br /&gt;
     public static void Main()&lt;br /&gt;
     {&lt;br /&gt;
         // create a base instance&lt;br /&gt;
         Window w = new Window(5,10);&lt;br /&gt;
         w.DrawWindow();&lt;br /&gt;
         // create a derived instance&lt;br /&gt;
         ListBox lb = new ListBox(20,30,&amp;quot;Hello world&amp;quot;);&lt;br /&gt;
         lb.DrawWindow();&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Hierarchy with two children class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Learning C# &lt;br /&gt;
by Jesse Liberty&lt;br /&gt;
Publisher: O&amp;quot;Reilly &lt;br /&gt;
ISBN: 0596003765&lt;br /&gt;
*/&lt;br /&gt;
 using System;&lt;br /&gt;
 class Window&lt;br /&gt;
 {&lt;br /&gt;
     // constructor takes two integers to&lt;br /&gt;
     // fix location on the console&lt;br /&gt;
     public Window(int top, int left)&lt;br /&gt;
     {&lt;br /&gt;
         this.top = top;&lt;br /&gt;
         this.left = left;&lt;br /&gt;
     }&lt;br /&gt;
     // simulates drawing the window&lt;br /&gt;
     public virtual void DrawWindow()&lt;br /&gt;
     {&lt;br /&gt;
         Console.WriteLine(&amp;quot;Window: drawing Window at {0}, {1}&amp;quot;,&lt;br /&gt;
             top, left);&lt;br /&gt;
     }&lt;br /&gt;
     // these members are protected and thus visible&lt;br /&gt;
     // to derived class methods. We&amp;quot;ll examine this&lt;br /&gt;
     // later in the chapter&lt;br /&gt;
     protected int top;&lt;br /&gt;
     protected int left;&lt;br /&gt;
 }&lt;br /&gt;
 // ListBox derives from Window&lt;br /&gt;
 class ListBox : Window&lt;br /&gt;
 {&lt;br /&gt;
     // constructor adds a parameter&lt;br /&gt;
     public ListBox(&lt;br /&gt;
         int top,&lt;br /&gt;
         int left,&lt;br /&gt;
         string contents):&lt;br /&gt;
         base(top, left)  // call base constructor&lt;br /&gt;
     {&lt;br /&gt;
         listBoxContents = contents;&lt;br /&gt;
     }&lt;br /&gt;
     // an overridden version (note keyword) because in the&lt;br /&gt;
     // derived method we change the behavior&lt;br /&gt;
     public override void DrawWindow()&lt;br /&gt;
     {&lt;br /&gt;
         base.DrawWindow();  // invoke the base method&lt;br /&gt;
         Console.WriteLine (&amp;quot;Writing string to the listbox: {0}&amp;quot;,&lt;br /&gt;
             listBoxContents);&lt;br /&gt;
     }&lt;br /&gt;
     private string listBoxContents;  // new member variable&lt;br /&gt;
 }&lt;br /&gt;
 class Button : Window&lt;br /&gt;
 {&lt;br /&gt;
     public Button(&lt;br /&gt;
         int top,&lt;br /&gt;
         int left):&lt;br /&gt;
         base(top, left)&lt;br /&gt;
     {&lt;br /&gt;
     }&lt;br /&gt;
     // an overridden version (note keyword) because in the&lt;br /&gt;
     // derived method we change the behavior&lt;br /&gt;
     public override void DrawWindow()&lt;br /&gt;
     {&lt;br /&gt;
         Console.WriteLine(&amp;quot;Drawing a button at {0}, {1}\n&amp;quot;,&lt;br /&gt;
             top, left);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 public class TesterClassArray1&lt;br /&gt;
 {&lt;br /&gt;
     static void Main()&lt;br /&gt;
     {&lt;br /&gt;
         Window win = new Window(1,2);&lt;br /&gt;
         ListBox lb = new ListBox(3,4,&amp;quot;Stand alone list box&amp;quot;);&lt;br /&gt;
         Button b = new Button(5,6);&lt;br /&gt;
         win.DrawWindow();&lt;br /&gt;
         lb.DrawWindow();&lt;br /&gt;
         b.DrawWindow();&lt;br /&gt;
         Window[] winArray = new Window[3];&lt;br /&gt;
         winArray[0] = new Window(1,2);&lt;br /&gt;
         winArray[1] = new ListBox(3,4,&amp;quot;List box in array&amp;quot;);&lt;br /&gt;
         winArray[2] = new Button(5,6);&lt;br /&gt;
         for (int i = 0;i &amp;lt; 3; i++)&lt;br /&gt;
         {&lt;br /&gt;
             winArray[i].DrawWindow();&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrate when constructors are called==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Demonstrate when constructors are called. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
// Create a base class. &lt;br /&gt;
class A { &lt;br /&gt;
  public A() {  &lt;br /&gt;
    Console.WriteLine(&amp;quot;Constructing A.&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Create a class derived from A. &lt;br /&gt;
class B : A { &lt;br /&gt;
  public B() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Constructing B.&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Create a class derived from B. &lt;br /&gt;
class C : B { &lt;br /&gt;
  public C() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Constructing C.&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class OrderOfConstruction { &lt;br /&gt;
  public static void Main() {&lt;br /&gt;
    C c = new C(); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Four layers of class hierarchy==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * C# Programmers Pocket Consultant&lt;br /&gt;
 * Author: Gregory S. MacBeth&lt;br /&gt;
 * Email: gmacbeth@comporium.net&lt;br /&gt;
 * Create Date: June 27, 2003&lt;br /&gt;
 * Last Modified Date:&lt;br /&gt;
 */&lt;br /&gt;
using System;&lt;br /&gt;
namespace Client.Chapter_5___Building_Your_Own_Classes&lt;br /&gt;
{&lt;br /&gt;
  public class MyMainClass3&lt;br /&gt;
  {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      //The function called is based&lt;br /&gt;
      //upon the type called by new.&lt;br /&gt;
      A MyA = new D();&lt;br /&gt;
      B MyB = new C();&lt;br /&gt;
      MyA.Display();    //Calls D Display  &lt;br /&gt;
      MyB.Display();    //Calls C Display&lt;br /&gt;
      // followed by B&amp;quot;s Display //via the base keyword&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  class A&lt;br /&gt;
  {&lt;br /&gt;
    public virtual void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class A&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  class B: A&lt;br /&gt;
  {&lt;br /&gt;
    public override void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class B&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  class C: B&lt;br /&gt;
  {&lt;br /&gt;
    public override void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class C&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
      base.Display();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  class D: C&lt;br /&gt;
  {&lt;br /&gt;
    public override void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class D&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates inheritance==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example7_1.cs illustrates inheritance&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
// declare the MotorVehicle class (the base class)&lt;br /&gt;
class MotorVehicle&lt;br /&gt;
{&lt;br /&gt;
  // declare the fields&lt;br /&gt;
  public string make;&lt;br /&gt;
  public string model;&lt;br /&gt;
  // define a constructor&lt;br /&gt;
  public MotorVehicle(string make, string model)&lt;br /&gt;
  {&lt;br /&gt;
    this.make = make;&lt;br /&gt;
    this.model = model;&lt;br /&gt;
  }&lt;br /&gt;
  // define a method&lt;br /&gt;
  public void Start()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(model + &amp;quot; started&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// declare the Car class (derived from the MotorVehicle base class)&lt;br /&gt;
class Car : MotorVehicle&lt;br /&gt;
{&lt;br /&gt;
  // declare an additional field&lt;br /&gt;
  public bool convertible;&lt;br /&gt;
  // define a constructor&lt;br /&gt;
  public Car(string make, string model, bool convertible) :&lt;br /&gt;
  base(make, model)  // calls the base class constructor&lt;br /&gt;
  {&lt;br /&gt;
    this.convertible = convertible;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// declare the Motorcycle class (derived from the MotorVehicle base class)&lt;br /&gt;
class Motorcycle : MotorVehicle&lt;br /&gt;
{&lt;br /&gt;
  // declare an additional field&lt;br /&gt;
  public bool sidecar;&lt;br /&gt;
  // define a constructor&lt;br /&gt;
  public Motorcycle(string make, string model, bool sidecar) :&lt;br /&gt;
  base(make, model)  // calls the base class constructor&lt;br /&gt;
  {&lt;br /&gt;
    this.sidecar = sidecar;&lt;br /&gt;
  }&lt;br /&gt;
  // define an additional method &lt;br /&gt;
  public void PullWheelie()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(model + &amp;quot; pulling a wheelie!&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example7_1&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    // declare a Car object, display the object&amp;quot;s fields, and call the&lt;br /&gt;
    // Start() method&lt;br /&gt;
    Car myCar = new Car(&amp;quot;Toyota&amp;quot;, &amp;quot;MR2&amp;quot;, true);&lt;br /&gt;
    Console.WriteLine(&amp;quot;myCar.make = &amp;quot; + myCar.make);&lt;br /&gt;
    Console.WriteLine(&amp;quot;myCar.model = &amp;quot; + myCar.model);&lt;br /&gt;
    Console.WriteLine(&amp;quot;myCar.convertible = &amp;quot; + myCar.convertible);&lt;br /&gt;
    myCar.Start();&lt;br /&gt;
    // declare a Motorcycle object, display the object&amp;quot;s fields, and call the&lt;br /&gt;
    // Start() method&lt;br /&gt;
    Motorcycle myMotorcycle = new Motorcycle(&amp;quot;Harley-Davidson&amp;quot;, &amp;quot;V-Rod&amp;quot;, false);&lt;br /&gt;
    Console.WriteLine(&amp;quot;myMotorcycle.make = &amp;quot; + myMotorcycle.make);&lt;br /&gt;
    Console.WriteLine(&amp;quot;myMotorcycle.model = &amp;quot; + myMotorcycle.model);&lt;br /&gt;
    Console.WriteLine(&amp;quot;myMotorcycle.sidecar = &amp;quot; + myMotorcycle.sidecar);&lt;br /&gt;
    myMotorcycle.Start();&lt;br /&gt;
    myMotorcycle.PullWheelie();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Illustrates versioning==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example7_5.cs illustrates versioning&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
// declare the MotorVehicle class&lt;br /&gt;
class MotorVehicle&lt;br /&gt;
{&lt;br /&gt;
  // declare the fields&lt;br /&gt;
  public string make;&lt;br /&gt;
  public string model;&lt;br /&gt;
  // define a constructor&lt;br /&gt;
  public MotorVehicle(string make, string model)&lt;br /&gt;
  {&lt;br /&gt;
    this.make = make;&lt;br /&gt;
    this.model = model;&lt;br /&gt;
  }&lt;br /&gt;
  // define the Accelerate() method&lt;br /&gt;
  public virtual void Accelerate()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;In MotorVehicle Accelerate() method&amp;quot;);&lt;br /&gt;
    Console.WriteLine(model + &amp;quot; accelerating&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// declare the Car class (derived from MotorVehicle)&lt;br /&gt;
class Car : MotorVehicle&lt;br /&gt;
{&lt;br /&gt;
  // define a constructor&lt;br /&gt;
  public Car(string make, string model) :&lt;br /&gt;
  base(make, model)&lt;br /&gt;
  {&lt;br /&gt;
    // do nothing&lt;br /&gt;
  }&lt;br /&gt;
  // define the Accelerate() method (uses the new keyword to&lt;br /&gt;
  // tell the compiler a new method is to be defined)&lt;br /&gt;
  public new void Accelerate()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;In Car Accelerate() method&amp;quot;);&lt;br /&gt;
    Console.WriteLine(model + &amp;quot; accelerating&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example7_5&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    // create a Car object&lt;br /&gt;
    Console.WriteLine(&amp;quot;Creating a Car object&amp;quot;);&lt;br /&gt;
    Car myCar = new Car(&amp;quot;Toyota&amp;quot;, &amp;quot;MR2&amp;quot;);&lt;br /&gt;
    // call the Car object&amp;quot;s Accelerate() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Calling myCar.Accelerate()&amp;quot;);&lt;br /&gt;
    myCar.Accelerate();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Inheritance 3==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * C# Programmers Pocket Consultant&lt;br /&gt;
 * Author: Gregory S. MacBeth&lt;br /&gt;
 * Email: gmacbeth@comporium.net&lt;br /&gt;
 * Create Date: June 27, 2003&lt;br /&gt;
 * Last Modified Date:&lt;br /&gt;
 */&lt;br /&gt;
using System;&lt;br /&gt;
namespace Client.Chapter_5___Building_Your_Own_Classes&lt;br /&gt;
{&lt;br /&gt;
  public class InheritanceChapter_5___Building_Your_Own_Classes&lt;br /&gt;
  {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      B MyB = new D();&lt;br /&gt;
      D MyD = new D();&lt;br /&gt;
      //Both result in in D&amp;quot;s instance of Display being //called&lt;br /&gt;
      MyB.Display();&lt;br /&gt;
      MyD.Display();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public class B&lt;br /&gt;
  {&lt;br /&gt;
    public virtual void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class B&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public class C: B&lt;br /&gt;
  {&lt;br /&gt;
    public override void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class C&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public class ContainedClass&lt;br /&gt;
  {&lt;br /&gt;
    int MyInt = 0;&lt;br /&gt;
  }&lt;br /&gt;
  public class D: C&lt;br /&gt;
  {&lt;br /&gt;
    public ContainedClass MyClass = new ContainedClass();&lt;br /&gt;
    public override void Display()&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Class D&amp;quot;s Display Method&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Pass a derived class reference to a base class reference==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Pass a derived class reference to a base class reference. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class TwoDShape { &lt;br /&gt;
  double pri_width;  // private &lt;br /&gt;
  double pri_height; // private &lt;br /&gt;
 &lt;br /&gt;
  // Default constructor. &lt;br /&gt;
  public TwoDShape() { &lt;br /&gt;
    width = height = 0.0; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor for TwoDShape. &lt;br /&gt;
  public TwoDShape(double w, double h) { &lt;br /&gt;
    width = w; &lt;br /&gt;
    height = h; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct object with equal width and height. &lt;br /&gt;
  public TwoDShape(double x) { &lt;br /&gt;
    width = height = x; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct object from an object. &lt;br /&gt;
  public TwoDShape(TwoDShape ob) { &lt;br /&gt;
    width = ob.width; &lt;br /&gt;
    height = ob.height; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Properties for width and height. &lt;br /&gt;
  public double width { &lt;br /&gt;
     get { return pri_width; } &lt;br /&gt;
     set { pri_width = value; } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public double height { &lt;br /&gt;
     get { return pri_height; } &lt;br /&gt;
     set { pri_height = value; } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void showDim() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Width and height are &amp;quot; + &lt;br /&gt;
                       width + &amp;quot; and &amp;quot; + height); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// A derived class of TwoDShape for triangles. &lt;br /&gt;
class Triangle : TwoDShape { &lt;br /&gt;
  string style; // private &lt;br /&gt;
   &lt;br /&gt;
  // A default constructor. &lt;br /&gt;
  public Triangle() { &lt;br /&gt;
    style = &amp;quot;null&amp;quot;; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor for Triangle. &lt;br /&gt;
  public Triangle(string s, double w, double h) : base(w, h) { &lt;br /&gt;
    style = s;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct an isosceles triangle. &lt;br /&gt;
  public Triangle(double x) : base(x) { &lt;br /&gt;
    style = &amp;quot;isosceles&amp;quot;;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct an object from an object. &lt;br /&gt;
  public Triangle(Triangle ob) : base(ob) { &lt;br /&gt;
    style = ob.style; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Return area of triangle. &lt;br /&gt;
  public double area() { &lt;br /&gt;
    return width * height / 2; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Display a triangle&amp;quot;s style. &lt;br /&gt;
  public void showStyle() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Triangle is &amp;quot; + style); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class Shapes7 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Triangle t1 = new Triangle(&amp;quot;right&amp;quot;, 8.0, 12.0); &lt;br /&gt;
 &lt;br /&gt;
    // make a copy of t1 &lt;br /&gt;
    Triangle t2 = new Triangle(t1); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t1: &amp;quot;); &lt;br /&gt;
    t1.showStyle(); &lt;br /&gt;
    t1.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t1.area()); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t2: &amp;quot;); &lt;br /&gt;
    t2.showStyle(); &lt;br /&gt;
    t2.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t2.area()); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Private field and public Property in inheritance==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
namespace nsInherit&lt;br /&gt;
{&lt;br /&gt;
    using System;&lt;br /&gt;
    &lt;br /&gt;
    public class clsMainInherit&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main ()&lt;br /&gt;
        {&lt;br /&gt;
            clsDerived derived = new clsDerived();&lt;br /&gt;
            derived.Property = 42;&lt;br /&gt;
            derived.ShowField();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
//&lt;br /&gt;
// Define a base class with a private field and a public Property&lt;br /&gt;
    class clsBase&lt;br /&gt;
    {&lt;br /&gt;
        private int m_Field;&lt;br /&gt;
        public int Property&lt;br /&gt;
        {&lt;br /&gt;
            get {return (m_Field);}&lt;br /&gt;
            set {m_Field = value;}&lt;br /&gt;
        }&lt;br /&gt;
        public void ShowField ()&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine (&amp;quot;The value of m_Field is &amp;quot; + m_Field);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
//&lt;br /&gt;
// Define a derived class that inherits from the clsBase&lt;br /&gt;
    class clsDerived : clsBase&lt;br /&gt;
    {&lt;br /&gt;
// For now, the derived class needs no members&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using base to overcome name hiding==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Using base to overcome name hiding. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class A { &lt;br /&gt;
  public int i = 0; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Create a derived class. &lt;br /&gt;
class B : A { &lt;br /&gt;
  new int i; // this i hides the i in A &lt;br /&gt;
 &lt;br /&gt;
  public B(int a, int b) { &lt;br /&gt;
    base.i = a; // this uncovers the i in A &lt;br /&gt;
    i = b; // i in B &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void show() { &lt;br /&gt;
    // this displays the i in A. &lt;br /&gt;
    Console.WriteLine(&amp;quot;i in base class: &amp;quot; + base.i); &lt;br /&gt;
 &lt;br /&gt;
    // this displays the i in B &lt;br /&gt;
    Console.WriteLine(&amp;quot;i in derived class: &amp;quot; + i); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class UncoverName1231 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    B ob = new B(1, 2); &lt;br /&gt;
 &lt;br /&gt;
    ob.show(); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>