Member Accessibility : Class Access Modifiers « Class Interface « C# / C Sharp






Member Accessibility

 


using System;

public class MotorVehicle {
    private string make;
    protected string model;

    public MotorVehicle(string make, string model) {
        this.make = make;
        this.model = model;
    }
    public virtual void Start() {
        TurnStarterMotor();
        System.Console.WriteLine("Vehicle started");
    }

    private void TurnStarterMotor() {
        System.Console.WriteLine("Turning starter motor...");
    }
}

public class Product : MotorVehicle {
    public Product(string make, string model) :
        base(make, model) {
        // do nothing
    }
    public override void Start() {
        Console.WriteLine("Starting " + model);
        base.Start();
    }
}
class MainClass {
    public static void Main() {

        Product myProduct = new Product("Toyota", "MR2");
        myProduct.Start();
    }

}

 








Related examples in the same category

1.Using Access Modifiers
2.Member Hiding
3.Demonstrate protectedDemonstrate protected
4.Public vs private accessPublic vs private access
5.illustrates member accessibilityillustrates member accessibility
6.illustrates member hidingillustrates member hiding
7.Illustrates the use of various access modifiersIllustrates the use of various access modifiers