All three ways of calling new() are equivalent in the code below package A; sub new { my (\$class, \$param) = @_; return bless {param => \$param}, \$class; } package main; my \$a1 = A->new('foo'); my \$a2 = new A('foo'); my \$a3 = A::new('A', 'foo');
B
Correct answer
Explanation
A->new('foo') passes 'A' as \$class and 'foo' as \$param (correct). new A('foo') also passes 'A' as \$class and 'foo' as \$param (correct). However, A::new('A', 'foo') is NOT equivalent - it bypasses Perl's inheritance mechanism and directly calls the subroutine, which fails if new() is inherited from a parent class. The third form is methodologically different.