static void Main(string[] args) { Console.WriteLine("***** Basic Inheritance *****\n"); Car myCar = new Car(80); myCar.Speed = 50; Console.WriteLine("My car is going to {0} MPH", myCar.Speed); MiniVan myVan = new MiniVan(); myVan.Speed = 10; Console.WriteLine("My van is going {0} MPH", myVan.Speed); // myVan.currSpeed = 55; Console.ReadLine(); }
static void Main(string[] args) { Car myCar = new Car(80); myCar.Speed = 50; Console.WriteLine("My car is going {0} MPH", myCar.Speed); MiniVan myVan = new MiniVan(); myVan.Speed = 50; Console.WriteLine("My van is going {0} MPH", myVan.Speed); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("**** Basic Inheirtance *****"); Car myCar = new Car(80); myCar.Speed = 50; Console.WriteLine("My car is going {0} MPH", myCar.Speed); MinVan myVar = new MinVan(); myVar.Speed = 10; Console.WriteLine("My van is going {0} MPH", myVar.Speed); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Basic Inhheritance *****\n"); // Make a Car object and set max speed. Car myCar = new Car(80); // Set the current speed, and print it. myCar.Speed = 50; Console.WriteLine("My car is going {0} MPH", myCar.Speed); // Now make a MiniVan object. MiniVan myVan = new MiniVan(); myVan.Speed = 10; Console.WriteLine("My van is going {0} MPH", myVan.Speed); // Error! Can't access private members! // myVan.currSpeed = 55; Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("***** Basic Inheritance *****\n"); //make a car obj and set max speed Car myCar = new Car(80); //set current speed and print it myCar.Speed = 50; Console.WriteLine("My car is going {0} MPH", myCar.Speed); //make a minivan MiniVan mv = new MiniVan(); //OK bc Speed is a public member mv.Speed = 10; //NOT OK bc currSpeed is a private member of parent class //mv.currSpeed = 10; Console.WriteLine("My van is going {0} MPH", mv.Speed); //ERROR! Can't access private members //mv.currSpeed=55; Console.ReadLine(); }
static void Main(string[] args) { Car myCar = new Car(80); myCar.Speed = 50; Console.WriteLine("My car is going {0} MPH", myCar.Speed); MiniVan myVan = new MiniVan(); myVan.Speed = 10; Console.WriteLine("My van is going {0} MPH", myVan.Speed); List<Car> myCars = new List<Car>(); for (int i = 40; i < 90; i++) { myCars.Add(new MiniVan(i)); } foreach (Car c in myCars) { Console.WriteLine("My car is going {0} MPH", c.maxSpeed); } Console.ReadLine(); }