<?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_Access_Modifiers</id>
		<title>Csharp/C Sharp/Class Interface/Class Access Modifiers - История изменений</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_Access_Modifiers"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Access_Modifiers&amp;action=history"/>
		<updated>2026-04-29T20:50:39Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Class_Access_Modifiers&amp;diff=620&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_Access_Modifiers&amp;diff=620&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_Access_Modifiers&amp;diff=621&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_Access_Modifiers&amp;diff=621&amp;oldid=prev"/>
				<updated>2010-05-26T11:39:14Z</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;==Demonstrate protected==&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 protected. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class B { &lt;br /&gt;
  protected int i, j; // private to B, but accessible by D &lt;br /&gt;
 &lt;br /&gt;
  public void set(int a, int b) { &lt;br /&gt;
    i = a; &lt;br /&gt;
    j = b; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void show() { &lt;br /&gt;
    Console.WriteLine(i + &amp;quot; &amp;quot; + j); &lt;br /&gt;
 } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class D : B { &lt;br /&gt;
  int k; // private &lt;br /&gt;
 &lt;br /&gt;
  // D can access B&amp;quot;s i and j &lt;br /&gt;
  public void setk() { &lt;br /&gt;
     k = i * j; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void showk() { &lt;br /&gt;
    Console.WriteLine(k); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class ProtectedDemo { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    D ob = new D(); &lt;br /&gt;
 &lt;br /&gt;
    ob.set(2, 3); // OK, known to D &lt;br /&gt;
    ob.show();    // OK, known to D &lt;br /&gt;
 &lt;br /&gt;
    ob.setk();  // OK, part of D &lt;br /&gt;
    ob.showk(); // OK, part of D &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 member accessibility==&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_3.cs illustrates member accessibility&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;
  private   string make;&lt;br /&gt;
  protected 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 Start() method (may be overridden in a&lt;br /&gt;
  // derived class)&lt;br /&gt;
  public virtual void Start()&lt;br /&gt;
  {&lt;br /&gt;
    TurnStarterMotor();&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Vehicle started&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  // define the TurnStarterMotor() method&lt;br /&gt;
  private void TurnStarterMotor()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Turning starter motor...&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;
  // override the base class Start() method&lt;br /&gt;
  public override void Start()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;Starting &amp;quot; + model);  // model accessible&lt;br /&gt;
    base.Start();  // calls the Start() method in the base class&lt;br /&gt;
    // Console.WriteLine(&amp;quot;make = &amp;quot; + make);  // make is not accessible&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example7_3&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    // create a Car object and call the object&amp;quot;s Accelerate() method&lt;br /&gt;
    Car myCar = new Car(&amp;quot;Toyota&amp;quot;, &amp;quot;MR2&amp;quot;);&lt;br /&gt;
    myCar.Start();&lt;br /&gt;
    // make and model are not accessible, so the following two lines&lt;br /&gt;
    // are commented out&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;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates member 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;
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_4.cs illustrates member hiding&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;
    Console.WriteLine(&amp;quot;In MotorVehicle constructor&amp;quot;);&lt;br /&gt;
    this.make = make;&lt;br /&gt;
    this.model = model;&lt;br /&gt;
    Console.WriteLine(&amp;quot;this.make = &amp;quot; + this.make);&lt;br /&gt;
    Console.WriteLine(&amp;quot;this.model = &amp;quot; + this.model);&lt;br /&gt;
  }&lt;br /&gt;
  // define the DisplayModel() method&lt;br /&gt;
  public void DisplayModel()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;In MotorVehicle DisplayModel() method&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;model = &amp;quot; + model);&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;
  // hide the base class model field&lt;br /&gt;
  public new string model;&lt;br /&gt;
  // define a constructor&lt;br /&gt;
  public Car(string make, string model) :&lt;br /&gt;
  base(make, &amp;quot;Test&amp;quot;)&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;In Car constructor&amp;quot;);&lt;br /&gt;
    this.model = model;&lt;br /&gt;
    Console.WriteLine(&amp;quot;this.model = &amp;quot; + this.model);&lt;br /&gt;
  }&lt;br /&gt;
  // hide the base class DisplayModel() method&lt;br /&gt;
  public new void DisplayModel()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;In Car DisplayModel() method&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;model = &amp;quot; + model);&lt;br /&gt;
    base.DisplayModel();  // calls DisplayModel() in the base class&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example7_4&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;
    Console.WriteLine(&amp;quot;Back in Main() method&amp;quot;);&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;
    // call the Car object&amp;quot;s DisplayModel() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Calling myCar.DisplayModel()&amp;quot;);&lt;br /&gt;
    myCar.DisplayModel();&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 the use of various access modifiers==&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;
  Example5_10.cs illustrates the use of various&lt;br /&gt;
  access modifiers&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// declare the Car class&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
  // declare the fields&lt;br /&gt;
  public             string make;&lt;br /&gt;
  protected internal string model;&lt;br /&gt;
  internal           string color;&lt;br /&gt;
  protected          int horsepower = 150;&lt;br /&gt;
  private            int yearBuilt;&lt;br /&gt;
  // define the methods&lt;br /&gt;
  public void SetYearBuilt(int yearBuilt)&lt;br /&gt;
  {&lt;br /&gt;
    this.yearBuilt = yearBuilt;&lt;br /&gt;
  }&lt;br /&gt;
  public int GetYearBuilt()&lt;br /&gt;
  {&lt;br /&gt;
    return yearBuilt;&lt;br /&gt;
  }&lt;br /&gt;
  public void Start()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Starting car ...&amp;quot;);&lt;br /&gt;
    TurnStarterMotor();&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Car started&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  private void TurnStarterMotor()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Turning starter motor ...&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example5_10&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    // create a Car object&lt;br /&gt;
    Car myCar = new Car();&lt;br /&gt;
    // assign values to the Car object fields&lt;br /&gt;
    myCar.make = &amp;quot;Toyota&amp;quot;;&lt;br /&gt;
    myCar.model = &amp;quot;MR2&amp;quot;;&lt;br /&gt;
    myCar.color = &amp;quot;black&amp;quot;;&lt;br /&gt;
    // myCar.horsepower = 200;  // protected field not accessible&lt;br /&gt;
    // myCar.yearBuilt = 1995;  // private field not accessible&lt;br /&gt;
    // call the SetYearBuilt() method to set the private yearBuilt field&lt;br /&gt;
    myCar.SetYearBuilt(1995);&lt;br /&gt;
    // display the values for the Car object fields&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.make = &amp;quot; + myCar.make);&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.model = &amp;quot; + myCar.model);&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.color = &amp;quot; + myCar.color);&lt;br /&gt;
    // call the GetYearBuilt() method to get the private yearBuilt field&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.GetYearBuilt() = &amp;quot; + myCar.GetYearBuilt());&lt;br /&gt;
    // call the Start() method&lt;br /&gt;
    myCar.Start();&lt;br /&gt;
    // myCar.TurnStarterMotor();  // private method not accessible&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;
==Member Accessibility==&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;
using System;&lt;br /&gt;
public class MotorVehicle {&lt;br /&gt;
    private string make;&lt;br /&gt;
    protected string model;&lt;br /&gt;
    public MotorVehicle(string make, string model) {&lt;br /&gt;
        this.make = make;&lt;br /&gt;
        this.model = model;&lt;br /&gt;
    }&lt;br /&gt;
    public virtual void Start() {&lt;br /&gt;
        TurnStarterMotor();&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;Vehicle started&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    private void TurnStarterMotor() {&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;Turning starter motor...&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Product : MotorVehicle {&lt;br /&gt;
    public Product(string make, string model) :&lt;br /&gt;
        base(make, model) {&lt;br /&gt;
        // do nothing&lt;br /&gt;
    }&lt;br /&gt;
    public override void Start() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;Starting &amp;quot; + model);&lt;br /&gt;
        base.Start();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        Product myProduct = new Product(&amp;quot;Toyota&amp;quot;, &amp;quot;MR2&amp;quot;);&lt;br /&gt;
        myProduct.Start();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Member Hiding==&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;
using System;&lt;br /&gt;
public class MotorVehicle {&lt;br /&gt;
    public string make;&lt;br /&gt;
    public string model;&lt;br /&gt;
    public MotorVehicle(string make, string model) {&lt;br /&gt;
        Console.WriteLine(&amp;quot;In MotorVehicle constructor&amp;quot;);&lt;br /&gt;
        this.make = make;&lt;br /&gt;
        this.model = model;&lt;br /&gt;
        Console.WriteLine(&amp;quot;this.make = &amp;quot; + this.make);&lt;br /&gt;
        Console.WriteLine(&amp;quot;this.model = &amp;quot; + this.model);&lt;br /&gt;
    }&lt;br /&gt;
    public void DisplayModel() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;In MotorVehicle DisplayModel() method&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;model = &amp;quot; + model);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Product : MotorVehicle {&lt;br /&gt;
    public new string model;&lt;br /&gt;
    public Product(string make, string model) :&lt;br /&gt;
        base(make, &amp;quot;Test&amp;quot;) {&lt;br /&gt;
        Console.WriteLine(&amp;quot;In Product constructor&amp;quot;);&lt;br /&gt;
        this.model = model;&lt;br /&gt;
        Console.WriteLine(&amp;quot;this.model = &amp;quot; + this.model);&lt;br /&gt;
    }&lt;br /&gt;
    public new void DisplayModel() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;In Product DisplayModel() method&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;model = &amp;quot; + model);&lt;br /&gt;
        base.DisplayModel();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;Creating a Product object&amp;quot;);&lt;br /&gt;
        Product myProduct = new Product(&amp;quot;Toyota&amp;quot;, &amp;quot;MR2&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Back in Main() method&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;myProduct.make = &amp;quot; + myProduct.make);&lt;br /&gt;
        Console.WriteLine(&amp;quot;myProduct.model = &amp;quot; + myProduct.model);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Calling myProduct.DisplayModel()&amp;quot;);&lt;br /&gt;
        myProduct.DisplayModel();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Public vs private access==&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;
// Public vs private access. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class MyClass {  &lt;br /&gt;
  private int alpha; // private access explicitly specified &lt;br /&gt;
  int beta;          // private access by default &lt;br /&gt;
  public int gamma;  // public access &lt;br /&gt;
 &lt;br /&gt;
  /* Methods to access alpha and beta.  It is OK for a &lt;br /&gt;
     member of a class to access a private member &lt;br /&gt;
     of the same class. &lt;br /&gt;
  */ &lt;br /&gt;
  public void setAlpha(int a) { &lt;br /&gt;
    alpha = a;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public int getAlpha() { &lt;br /&gt;
    return alpha; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void setBeta(int a) { &lt;br /&gt;
    beta = a;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public int getBeta() { &lt;br /&gt;
    return beta; &lt;br /&gt;
  } &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
public class AccessDemo {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    MyClass ob = new MyClass();  &lt;br /&gt;
  &lt;br /&gt;
    /* Access to alpha and beta is allowed only &lt;br /&gt;
       through methods. */ &lt;br /&gt;
    ob.setAlpha(-99); &lt;br /&gt;
    ob.setBeta(19); &lt;br /&gt;
    Console.WriteLine(&amp;quot;ob.alpha is &amp;quot; + ob.getAlpha()); &lt;br /&gt;
    Console.WriteLine(&amp;quot;ob.beta is &amp;quot; + ob.getBeta()); &lt;br /&gt;
 &lt;br /&gt;
    // You cannot access alpha or beta like this: &lt;br /&gt;
//  ob.alpha = 10; // Wrong! alpha is private! &lt;br /&gt;
//  ob.beta = 9;   // Wrong! beta is private! &lt;br /&gt;
 &lt;br /&gt;
    // It is OK to directly access gamma because it is public. &lt;br /&gt;
    ob.gamma = 99;  &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 Access Modifiers==&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;
public class Product {&lt;br /&gt;
    public string make;&lt;br /&gt;
    protected internal string model;&lt;br /&gt;
    internal string color;&lt;br /&gt;
    protected int horsepower = 150;&lt;br /&gt;
    private int yearBuilt;&lt;br /&gt;
    public void SetYearBuilt(int yearBuilt) {&lt;br /&gt;
        this.yearBuilt = yearBuilt;&lt;br /&gt;
    }&lt;br /&gt;
    public int GetYearBuilt() {&lt;br /&gt;
        return yearBuilt;&lt;br /&gt;
    }&lt;br /&gt;
    public void Start() {&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;Starting Product ...&amp;quot;);&lt;br /&gt;
        TurnStarterMotor();&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;Product started&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    private void TurnStarterMotor() {&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;Turning starter motor ...&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        Product myProduct = new Product();&lt;br /&gt;
        myProduct.make = &amp;quot;Toyota&amp;quot;;&lt;br /&gt;
        myProduct.model = &amp;quot;MR2&amp;quot;;&lt;br /&gt;
        myProduct.color = &amp;quot;black&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        myProduct.SetYearBuilt(1995);&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;myProduct.make = &amp;quot; + myProduct.make);&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;myProduct.model = &amp;quot; + myProduct.model);&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;myProduct.color = &amp;quot; + myProduct.color);&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;myProduct.GetYearBuilt() = &amp;quot; + myProduct.GetYearBuilt());&lt;br /&gt;
        myProduct.Start();&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>