PolyMorphism

PolyMorphism

Poly – means many , Morphism – mean form

  • A person behaves as a mum in house while at the same time, a person behaves like an employee in the office
  • There are two types of polymorphism. Dynamic and Static

– Static: Method overloading in the same class

  • Having more than one methods in a class with the same name and different param(s)
public void method1(int x) {

console.writelin("Test ")

}

public void method(String x) {

console.writeln("String ", x);

}c

 

 

– Dynamic:  Method overriding in different class

  •  Having duplicate methods in base and derived class with the same name as well as same param(s)
  public abstract class AbstractBaseClass {

 public abstract void AbstractMethod();

public virtual void VirtualMethod()  {

Console.WriteLine("Virtual Method in Base Class");  }

}

 

public class AbstractDerivedClass : AbstractBaseClass {

public override void AbstractMethod() {

Console.WriteLine("Abstract Method in Derived Class");

}

public override void VirtualMethod() {

base.VirtualMethod();

Console.WriteLine("Oh, I have message from Base Class");

}

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *