MCQs on Advanced OOP Features | Perl

Dive deeper into Perl’s Object-Oriented Programming (OOP) with advanced features like inheritance, polymorphism, roles, traits, and method modifiers using Moose and Moo. Enhance your OOP skills with these concepts.


Inheritance and Polymorphism (10 Questions)

  1. What is inheritance in Perl OOP?
    A) The ability to create objects
    B) The ability of one class to use the methods and properties of another class
    C) The ability to modify objects at runtime
    D) The ability to clone objects
  2. Which keyword is used in Perl to declare inheritance?
    A) extends
    B) inherit
    C) use
    D) super
  3. In Perl, how do you call a method from a parent class in a subclass?
    A) super->method_name()
    B) parent->method_name()
    C) self->method_name()
    D) class->method_name()
  4. What is polymorphism in Perl OOP?
    A) Multiple classes can share the same method name
    B) A class can have multiple constructors
    C) A class can inherit from multiple classes
    D) A method can be overloaded with different parameter types
  5. Which operator allows method overloading in Perl?
    A) overload
    B) ++
    C) &
    D) .
  6. How do you define a subclass in Perl using inheritance?
    A) class SubClass inherits BaseClass
    B) package SubClass; @ISA = qw(BaseClass);
    C) extends BaseClass;
    D) class SubClass extends BaseClass
  7. Which keyword is used in Perl to access the parent class’s methods and properties?
    A) super
    B) base
    C) parent
    D) isa
  8. In polymorphism, how can you override a method from a parent class in a subclass?
    A) By using override keyword
    B) By redefining the method with the same name
    C) By using the polymorphic keyword
    D) By using call_parent()
  9. What is the benefit of polymorphism in OOP?
    A) It allows for code duplication
    B) It allows the same method to behave differently based on the object
    C) It improves the performance of the code
    D) It restricts method accessibility
  10. What method is typically used to call a parent class constructor in Perl?
    A) SUPER::new()
    B) parent->new()
    C) class->new()
    D) base->new()

Roles and Traits (Using Moose and Moo) (10 Questions)

  1. What is the main purpose of roles in Perl OOP?
    A) To define the properties of a class
    B) To allow code sharing between unrelated classes
    C) To provide inheritance for a class
    D) To manage method overloading
  2. Which module provides role-based programming in Perl?
    A) Moose::Role
    B) Moo::Role
    C) Role::Tiny
    D) Moose::Meta::Role
  3. In Moose, how do you apply a role to a class?
    A) with 'RoleName';
    B) use RoleName;
    C) apply 'RoleName';
    D) extends 'RoleName';
  4. How are roles different from inheritance in Perl OOP?
    A) Roles can only be applied to classes
    B) Inheritance allows a class to inherit methods from another class, while roles provide reusable behavior without hierarchy
    C) Roles provide stronger typing than inheritance
    D) Roles prevent the subclass from accessing parent methods
  5. Which of the following is a trait of Moo in Perl?
    A) Lightweight alternative to Moose
    B) Provides advanced inheritance support
    C) Only works with hash-based objects
    D) Implements method overloading
  6. How do you define a method in a Moose role?
    A) method method_name {}
    B) sub method_name {}
    C) has method_name => sub {}
    D) build method_name {}
  7. What is the difference between Moose and Moo?
    A) Moose is faster than Moo
    B) Moo is a lighter version of Moose with fewer features
    C) Moose does not support roles
    D) Moo is a deprecated version of Moose
  8. What does the with keyword do in Perl when using roles?
    A) It includes a role in the class definition
    B) It calls a method from a role
    C) It defines a new method in a role
    D) It creates an alias for a method
  9. How do you create a role with Moo?
    A) package RoleName; use Moo::Role;
    B) package RoleName; use Moo;
    C) package RoleName; sub method_name {}
    D) package RoleName; extends Moo::Role;
  10. Which of these is a valid feature of Moose roles?
    A) They can define constructors
    B) They cannot contain methods
    C) They can be composed into multiple classes
    D) They are not reusable

Advanced Method Modifiers (10 Questions)

  1. What is a method modifier in Perl OOP?
    A) A way to modify the behavior of a method
    B) A tool to change the name of a method
    C) A way to create new methods dynamically
    D) A type of inheritance
  2. Which modifier allows a method to be called before its original implementation in Perl?
    A) before
    B) after
    C) around
    D) prepend
  3. What does the after method modifier do in Perl OOP?
    A) It executes code before the original method
    B) It executes code after the original method
    C) It replaces the original method entirely
    D) It prevents the original method from running
  4. How do you apply a method modifier in Perl OOP?
    A) Using the method keyword
    B) Using before, after, or around on a method definition
    C) By using apply on the class
    D) By extending a parent class method
  5. What is the purpose of the around method modifier in Perl?
    A) It allows modification of a method’s arguments and results
    B) It replaces a method entirely
    C) It ensures a method is called after the constructor
    D) It prevents the method from being called
  6. Which module provides the before, after, and around method modifiers in Perl?
    A) Moose
    B) Moo
    C) Method::Modifiers
    D) Moose::Meta::Method
  7. How does before method modifier differ from after?
    A) before executes code after the method; after executes before
    B) before modifies return values; after modifies arguments
    C) before executes code before the method, after executes after
    D) There is no difference between before and after
  8. Which of these is NOT a valid method modifier in Moose?
    A) before
    B) after
    C) around
    D) finally
  9. How do you prevent a method in Perl from executing its original functionality?
    A) Using the noexec modifier
    B) Using the around modifier and not calling the original method
    C) Using the block modifier
    D) Using die() within the method
  10. In Perl, what does the Method::Modifiers module provide?
    A) It allows inheritance to be used in method definitions
    B) It provides modifiers like before, after, and around
    C) It enables the definition of private methods
    D) It allows method chaining

Answers Table

QNoAnswer (Option with Text)
1B) The ability of one class to use the methods and properties of another class
2A) extends
3A) super->method_name()
4A) Multiple classes can share the same method name
5A) overload
6B) package SubClass; @ISA = qw(BaseClass);
7A) super
8B) By redefining the method with the same name
9B) It allows the same method to behave differently based on the object
10A) SUPER::new()
11B) To allow code sharing between unrelated classes
12A) Moose::Role
13A) with 'RoleName';
14B) Inheritance allows a class to inherit methods from another class, while roles provide reusable behavior without hierarchy
15A) Lightweight alternative to Moose
16A) method method_name {}
17B) Moo is a lighter version of Moose with fewer features
18A) It includes a role in the class definition
19A) package RoleName; use Moo::Role;
20C) They can be composed into multiple classes
21A) A way to modify the behavior of a method
22A) before
23B) It executes code after the original method
24B) Using before, after, or around on a method definition
25A) It allows modification of a method’s arguments and results
26C) Method::Modifiers
27C) before executes code before the method, after executes after
28D) finally
29B) Using the around modifier and not calling the original method
30B) It provides modifiers like before, after, and around

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top