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)
What does OOP stand for? A) Object-Oriented Programming B) Object Operational Processing C) Organized Object Programming D) Object-Oriented Processing
Which feature is central to OOP? A) Functional programming B) Encapsulation C) Inline scripts D) Regular expressions
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
Which OOP principle allows code reuse by creating subclasses? A) Polymorphism B) Encapsulation C) Inheritance D) Abstraction
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
Which feature hides implementation details from users? A) Encapsulation B) Inheritance C) Polymorphism D) Abstraction
In Perl, OOP is implemented using what? A) Packages B) Classes C) Objects D) All of the above
Which keyword is used to create an instance of a class? A) new B) create C) initialize D) define
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
Which Perl pragma helps enforce strict OOP conventions? A) strict B) warnings C) strict::Object D) OOP::strict
Creating Classes and Objects (10 Questions)
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
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
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
How do you create an object in Perl? A) $object = Class->new(); B) $object = new Class(); C) $object = bless {}; D) All of the above
What data type does bless work with? A) Scalars B) Arrays C) Hashes or references D) Functions
In Perl, a constructor is typically implemented using which method? A) init B) build C) new D) create
How do you access an object method in Perl? A) $object->method(); B) method->object(); C) $object.method(); D) call $object->method;
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
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
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)
Which is the default constructor name in Perl? A) build B) construct C) new D) initialize
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
How are methods defined in Perl? A) Using the sub keyword B) Using method keyword C) As anonymous functions D) By prefixing with @
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 {}
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
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
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
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
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()
Which module provides advanced OOP capabilities in Perl? A) Moose B) Moo C) Mouse D) All of the above
Answers Table
QNo
Answer (Option with Text)
1
A) Object-Oriented Programming
2
B) Encapsulation
3
A) Combines data and methods into a single unit
4
C) Inheritance
5
A) The same method name to perform different tasks