nilkanth

nilkanth

  • NA
  • 1
  • 0

Polymorphism

Oct 1 2004 6:21 AM
I want to know whether this statement is true.. If you are not overriding a virtual method of base class in derived class, you can’t use base class method by using base keyword in derived class. Also when you will create an instance of derived class, it will call derived class method and you will only be able to access base class method when you will create instance of base class. public class Person { protected string ssn = "444-55-6666"; protected string name = "John L. Malgraine"; public virtual void GetInfo() { Console.WriteLine("Name: {0}", name); Console.WriteLine("SSN: {0}", ssn); } } class Employee: Person { public string id = "ABC567EFG"; public void GetInfo() { // Calling the base class GetInfo method: base.GetInfo(); Console.WriteLine("Employee ID: {0}", id); } } class TestClass { public static void Main() { Employee E = new Employee(); E.GetInfo(); } } But the above program works for me... Can anybody explain?!?!?

Answers (1)