static void Main(string[] args) { Animal whiskers = new Animal() { Name = "Whiskers", Sound = "Meow" }; Dog grovers = new Dog() { Name = "Grover", Sound = "Woof", Sound2 = "Grrr" //Remember, the derived, Dog, class has a 'Sound2' property but the base class doesn't!!!! }; grovers.Sound = "Wooooooof"; whiskers.MakeSound(); grovers.MakeSound(); whiskers.SetAnimalIdInfo(123, "Sally Smith"); grovers.SetAnimalIdInfo(456, "Paul Brown"); whiskers.GetAnimalIDInfo(); grovers.GetAnimalIDInfo(); if (grovers is Animal) { Console.WriteLine("Yes, grovers is both a dog and animal."); } //Must reference outer class to get to the inner class Animal.AnimalHealth getHealth = new Animal.AnimalHealth(); Console.WriteLine("Is my animal healthy: {0}", getHealth.HealthyWeight(11, 46)); //True Console.WriteLine("Is my animal healthy: {0}", getHealth.HealthyWeight(11, 176)); //False Animal monkey = new Animal() //This creates a new animal using the animal constructor. { Name = "Happy", Sound = "Eeeeee" }; Animal spot = new Dog() //This creates a new animal using the dog constructor. { Name = "Spot", Sound = "Woooof", Sound2 = "Geeerrr" }; monkey.MakeSound(); spot.MakeSound(); //Without overriding the method in the Dog class, this will using the 'MakeSound' method in animal because the dog is created as an animal. Console.ReadLine(); }
static void Main(string[] args) { Animal whiskers = new Animal() { Name = "Whiskers", Sound = "Meow" }; Dog grover = new Dog() { Name = "Grover", Sound = "Woof", Sound2 = "Grrr" }; grover.Sound = "Wooooof"; whiskers.MakeSound(); grover.MakeSound(); whiskers.SetAnimalIDinfo(12345, "Sally Smith"); grover.SetAnimalIDinfo(12346, "Paul Brown"); whiskers.GetAnimalIDInfo(); grover.GetAnimalIDInfo(); Animal.AnimalHealth getHealth = new Animal.AnimalHealth(); Console.WriteLine("Is my animal healthy : {0}", getHealth.HealtWeight(11, 146)); Animal monkey = new Animal() { Name = "Happy", Sound = "Eeeeee" }; Animal spot = new Dog() { Name = "Spot", Sound = "Wooof", Sound2 = "Geeerrrr" }; monkey.MakeSound(); spot.MakeSound(); Console.ReadLine(); }