Multiple choice technology programming languages

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

  1. A

  2. B

  3. the code will fail

  4. None of the above

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

Calling B->new() inherits new from package A. In A::new, the single-argument bless {} blesses the object into the current package (A). Thus, \$obj is an instance of A, and \$obj->foo() calls A::foo which returns 'A'.