#!/usr/bin/perl

# Virtual Functions demonstrated.

use strict;

# Call a function from an object.
sub test01
{
  use Fruit;
  my $x0 = Fruit->init;
  $x0->printing;
}

#test01;

# Test overloaded function.
sub test02
{
  use Apple;
  my $x1 = Apple->init;
  $x1->printing;
}

#test02;

# Virtual function test:  assign x the object and 
#   the correct printing function is called.
sub test03
{
  use Fruit;
  use Apple;
  my $x0 = Fruit->init;
  my $x1 = Apple->init;

  my $x = $x0;
  $x->printing;
  $x = $x1;
  $x->printing;
}

########test03;

sub printfruit
{
  my $x = shift;

  $x->printing;
}

# Demonstrate that the virtual function will match by passing
#  it through a function call.
sub test04
{
  
  use Fruit;
  my $x0 = Fruit->init;
  printfruit($x0);

  use Apple;
  $x0 = Apple->init;
  printfruit($x0);
}

test04;

  

