Workshop

Quiz

1:The first argument passed to an object method is always
  1. The class name

  2. The originally blessed reference

  3. Whatever the first argument was when you invoked the method

2:Can you have method names with the same names as built-in functions, or of already-defined subroutines?
  1. Yes, but it's difficult, as noted in Hour 8, “Functions.”

  2. Yes, and there are no concerns really.

  3. No, it's impossible.

3:Does the constructor subroutine in a class have to be called new?
  1. Yes

  2. No

Answers

A1: b. The reference that was blessed in the constructor is returned to each method. In this way the method gets a handle back to the object, and can use it to do its work.
A2: b. It's not really a problem because Perl can always tell that you meant the method—and not the built-in—because ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.