MCQs on Object-Oriented Programming in Perl | Perl

Explore the fundamentals of Object-Oriented Programming (OOP) in Perl. Dive into concepts like classes, objects, methods, and constructors to create scalable, modular, and reusable Perl code effortlessly.


Introduction to OOP Concepts (10 Questions)

  1. What does OOP stand for?
    A) Object-Oriented Programming
    B) Object Operational Processing
    C) Organized Object Programming
    D) Object-Oriented Processing
  2. Which feature is central to OOP?
    A) Functional programming
    B) Encapsulation
    C) Inline scripts
    D) Regular expressions
  3. What does encapsulation achieve in OOP?
    A) Combines data and methods into a single unit
    B) Increases code size
    C) Provides dynamic function calls
    D) Eliminates inheritance
  4. Which OOP principle allows code reuse by creating subclasses?
    A) Polymorphism
    B) Encapsulation
    C) Inheritance
    D) Abstraction
  5. What does polymorphism enable in Perl OOP?
    A) The same method name to perform different tasks
    B) Prevents function overloading
    C) Ensures type checking
    D) Disables inheritance
  6. Which feature hides implementation details from users?
    A) Encapsulation
    B) Inheritance
    C) Polymorphism
    D) Abstraction
  7. In Perl, OOP is implemented using what?
    A) Packages
    B) Classes
    C) Objects
    D) All of the above
  8. Which keyword is used to create an instance of a class?
    A) new
    B) create
    C) initialize
    D) define
  9. In Perl, which of the following is an example of a “class”?
    A) A package
    B) A module
    C) Both A and B
    D) A function
  10. Which Perl pragma helps enforce strict OOP conventions?
    A) strict
    B) warnings
    C) strict::Object
    D) OOP::strict

Creating Classes and Objects (10 Questions)

  1. How is a class defined in Perl?
    A) Using the class keyword
    B) By creating a package
    C) Using the object keyword
    D) Using class and object together
  2. What does the bless function do in Perl?
    A) Turns a reference into an object
    B) Initializes a class variable
    C) Imports a module
    D) Binds a function to a module
  3. What is typically passed as the first argument to a method?
    A) Package name
    B) Class name or object reference
    C) Method name
    D) Module name
  4. How do you create an object in Perl?
    A) $object = Class->new();
    B) $object = new Class();
    C) $object = bless {};
    D) All of the above
  5. What data type does bless work with?
    A) Scalars
    B) Arrays
    C) Hashes or references
    D) Functions
  6. In Perl, a constructor is typically implemented using which method?
    A) init
    B) build
    C) new
    D) create
  7. How do you access an object method in Perl?
    A) $object->method();
    B) method->object();
    C) $object.method();
    D) call $object->method;
  8. What is the purpose of @ISA in Perl OOP?
    A) Manages inheritance between classes
    B) Stores all object properties
    C) Defines encapsulation rules
    D) Enables method overloading
  9. Which of the following is a valid object initialization in Perl?
    A) $self = {}; bless $self, $class;
    B) $self = \%data; bless $self;
    C) bless {};
    D) All of the above
  10. How can you check if an object is an instance of a specific class?
    A) ref($object) eq 'Class';
    B) isa($object, 'Class');
    C) Class::is($object);
    D) object->isa('Class');

Using Methods and Constructors (10 Questions)

  1. Which is the default constructor name in Perl?
    A) build
    B) construct
    C) new
    D) initialize
  2. What happens if a constructor is not explicitly defined?
    A) Perl throws an error
    B) Objects cannot be created
    C) No constructor is required in Perl
    D) Default constructor must be imported
  3. How are methods defined in Perl?
    A) Using the sub keyword
    B) Using method keyword
    C) As anonymous functions
    D) By prefixing with @
  4. How are private methods conventionally named in Perl?
    A) With a prefix _ (underscore)
    B) Using uppercase letters
    C) With a .priv suffix
    D) Enclosed in {}
  5. What does $self represent in a method?
    A) The object or class the method is called on
    B) A reference to the method
    C) The data type of the class
    D) A variable storing method names
  6. How do you override a method in Perl?
    A) Redefine it in a subclass
    B) Use @ISA to change method behavior
    C) Directly edit the superclass
    D) Call the parent method explicitly
  7. Which of the following ensures that methods are inherited?
    A) The @EXPORT array
    B) The @ISA array
    C) Using use in the child class
    D) Defining all methods in the parent class
  8. What does $object->can('method') do?
    A) Checks if the object has the specified method
    B) Executes the specified method
    C) Converts a method into a class variable
    D) Generates the method for the object
  9. How do you call a parent class method from a subclass?
    A) SUPER::method()
    B) Parent::method()
    C) $self->method(SUPER)
    D) call SUPER->method()
  10. Which module provides advanced OOP capabilities in Perl?
    A) Moose
    B) Moo
    C) Mouse
    D) All of the above

Answers Table

QNoAnswer (Option with Text)
1A) Object-Oriented Programming
2B) Encapsulation
3A) Combines data and methods into a single unit
4C) Inheritance
5A) The same method name to perform different tasks
6D) Abstraction
7D) All of the above
8A) new
9C) Both A and B
10A) strict
11B) By creating a package
12A) Turns a reference into an object
13B) Class name or object reference
14D) All of the above
15C) Hashes or references
16C) new
17A) $object->method();
18A) Manages inheritance between classes
19D) All of the above
20A) ref($object) eq 'Class';
21C) new
22B) Objects cannot be created
23A) Using the sub keyword
24A) With a prefix _ (underscore)
25A) The object or class the method is called on
26A) Redefine it in a subclass
27B) The @ISA array
28A) Checks if the object has the specified method
29A) SUPER::method()
30D) All of the above

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