linux poison RSS
linux poison Email

Perl Script: Creating Method Override (Polymorphism)

Polymorphism means that methods defined in the base class will override methods defined in the parent classes and is mainly used to add or extend the functionality of an existing class without reprogramming the whole class.

The following simple Perl code demonstrate the concepts of Polymorphism (Method overriding):


package parent;
  sub foo {
    print "Inside the parent. \n";

# Inheritance is accomplished by placing the names of parent classes into a special array called @ISA.

package child;
  @ISA = (A);
  sub foo {
    print "Inside the child. \n";
package main;
Output: perl
Inside the child.


Post a Comment

Related Posts with Thumbnails