Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Part 23 - C# Tutorial - Polymorphism


Part 23 - C# Tutorial - Polymorphism


8 comments:

  1. Hello Venkat,

    I'm bit confused between new(shadow) and override keyword.Kindly explain what's the difference and when to use these.

    Thanks,
    Rohan

    ReplyDelete
    Replies
    1. Got my query resolved...
      The answer is in your next video.
      Thanks...

      Delete
  2. Hi Sir,

    There is a confusion. I have heard that there are two type of polymorphim.

    1.Compile Time
    2.Runtime

    I think the above video explains the runtime polymorphism.
    Kindly explain compile time polymorphism.

    ReplyDelete
  3. I think this is simplier way to explain polymorphism:

    Employee FTE = new FullTimeEmployee();
    FTE.PrintFullName();

    Employee E = new Employee();
    E.PrintFullName();


    ReplyDelete
  4. what are the uses of static key word and how should i use ?

    ReplyDelete
  5. Hi Venkat,

    I have one confusion about run time polymorphism. How one can say that overriding of method happens at run time and overloading at compile time.

    Thanks
    Rakesh

    ReplyDelete
    Replies
    1. as in run time if you choose the reference of base class and the object with new keyword is of child .... and the method u declared in the base class is virtual or abstract , and u have derived it in child class... now the instance u are generating is of type child but the reference is of parent ... so compiler is gonna look parent for the method u defined and then in child the particular method u have defined... it' not easy for compiler for to do so ...so what happens is that at run time which function is to be chosen is decided when the object is passed... this is run time polymorphism

      Delete
  6. contd.

    BaseClass bObj = New ChildClass()
    bObj.commonMethodName

    1> If Base method 'virtual'(Or 'override' in case on multi level inheritance) and child method 'override' -> child method executes
    2> If Base method is not 'virtual'(Or 'override' in case on multi level inheritance) and child method 'new'(optional, vs prompt) -> base method executes (Also called method hiding)

    ReplyDelete

If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.