Programming Languages C++ Subjective
Mar 13, 2013

“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?

Detailed Explanation

The above statement is a concept of Polymorphism in Perl. To clarify the statement, let’s take an example:

package X;
 
sub foo
 
{
 
print("Inside X::foo\n");
 
}
 
package Z;
 
@ISA = (X);
 
sub foo
 
{
 
print("Inside Z::foo\n");
 
}
 
package main;
 
Z->foo();

This program displays:

Inside Z::foo

- In the above example, the foo() method defined in class Z class overrides the inheritance from class X. Polymorphism is mainly used to add or extend the functionality of an existing class without reprogramming the whole class.

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback