Multiple choice technology programming languages

What will be the output ? package A; sub new { my $class = shift; return bless {}, $class; } package B; use base 'A'; sub foo { return 'blah'; } package main; my $obj = B->new(); print $obj->foo(), "\n";

  1. blah

  2. Empty String

  3. Can't locate object method "new" via package "B"

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Package B uses base 'A' to inherit from A, so B->new() calls A's constructor method which blesses an empty hashref. The returned object is a B instance that can call B's foo method, which returns 'blah'. The code prints 'blah' followed by a newline. Options B and C are incorrect because Perl's inheritance works properly and the foo method exists in package B.