KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Consider this code: class Program { static void Main(string[] args) { Person person = new Teacher(); person.ShowInfo(); Console.ReadLine(); } } public class Person { public void ShowInfo() { Console.WriteLine("I am Person"); } } public class Teacher : Person { public new void ShowInfo() { Console.WriteLine("I am Teacher"); } } When I run this code, the following is outputted: I am Person However, you can see that it is an instance of Teacher , not of Person . Why does the code do that?
Tags (comma-separated)
Save Edits
Cancel