Illustrates member accessibility in subclass : Derived Class : Class C# Examples


C# Examples » Class » Derived Class »

 

Illustrates member accessibility in subclass









    
using  System;

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

    public  Car(string  make,  string  model)
    {
        this.make  =  make;
        this.model  =  model;
    }

    public  virtual  void  Start()
    {
        startCar();
        System.Console.WriteLine("Vehicle  started");
    }

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

}

public  class  MyFirstCar  :  Car
{
    public  MyFirstCar(string  make,  string  model)  :  base(make,  model)
    {
    }

    public  override  void  Start()
    {
        Console.WriteLine("Starting  "  +  model);    
        base.Start();    
    }
}

class  MainClass
{
    public  static  void  Main()
    {
        MyFirstCar  myCar  =  new  MyFirstCar("Toyota",  "MR2");
        myCar.Start();
    }
}
    
   
  
   



Output

Starting MR2
Turning starter motor...
Vehicle started


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Derived Class