Q. What is the correct syntax for defining a class in Perl?

  • (A) package class_name
  • (B) class class_name
  • (C) new class class_name
  • (D) new package class_name
πŸ’¬ Discuss
βœ… Correct Answer: (A) package class_name
Explanation: The correct syntax for creating a class in Perl is:

package class_name

Q. Object in Perl an instance of a class?

  • (A) True
  • (B) False
  • (C) ---
  • (D) ---
πŸ’¬ Discuss
βœ… Correct Answer: (A) True
Explanation: Objects are instances of class.

Q. What is called when an object is created in Perl?

  • (A) Destructor
  • (B) Constructor
  • (C) Variable
  • (D) All of these
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of these
Explanation: The constructor of a class is the first subroutine to be called when an object of that class is initiated.

Q. What is the correct syntax for creating a new object in Perl?

  • (A) var object_name = new class_name()
  • (B) new object_name = class_name()
  • (C) my object_name = new class_name()
  • (D) None of these
πŸ’¬ Discuss
βœ… Correct Answer: (C) my object_name = new class_name()
Explanation: The correct syntax for creating an object in Perl is:

my object_name = new class_name()

Q. Which of these is not a type of method in Perl?

  • (A) Static method
  • (B) Constant method
  • (C) Virtual method
  • (D) All of these
πŸ’¬ Discuss
βœ… Correct Answer: (B) Constant method
Explanation: Virtual methods and static methods are valid types of methods in Perl.

Q. What will be the output of the following Perl code?

Code:
use strict;
use warnings;
package vehicle;

sub set_mileage{
    my $class = shift;
    
    my $self = {
        'distance'=> shift,
        'petrol_consumed'=> shift
    };
    
    bless $self, $class;
    return $self;
}

sub get_mileage{
    my $self = shift;
    my $result = $self->{'distance'} / $self->{'petrol_consumed'};
    
    print "$result\n";
}

my $ob1 = vehicle -> set_mileage(2550, 175);
$ob1->get_mileage();
  • (A) 15
  • (B) 15.00
  • (C) 14.5714285714286
  • (D) None of these
πŸ’¬ Discuss
βœ… Correct Answer: (C) 14.5714285714286

Q. Destructor's in Perl are ___.

  • (A) Used for cleanup of reference of objects
  • (B) Called at the start of the program
  • (C) Not a program
  • (D) All of these
πŸ’¬ Discuss
βœ… Correct Answer: (A) Used for cleanup of reference of objects
Explanation: Destructors in Perl are called when the object goes out of scope. It is used to clean up the reference of the object.

Q. What is method overwriting in Perl?

  • (A) Filling up method with extra written data
  • (B) Methods that provide extra features
  • (C) A Feature that allows rewriting of methods in child class
  • (D) All of these
πŸ’¬ Discuss
βœ… Correct Answer: (A) Filling up method with extra written data
Explanation: Method overwriting in Perl is a feature using which we can rewrite the method in child class.

Q. Method overwriting can be used to implement run time polymorphism?

  • (A) true
  • (B) false
  • (C) ---
  • (D) ---
πŸ’¬ Discuss
βœ… Correct Answer: (A) true
Explanation: Run time polymorphism is implemented in Perl using method overwriting.

Q. Which of these are valid type of inheritance in Perl?

  • (A) Multiple inheritance
  • (B) Multilevel inheritance
  • (C) Hierarchical inheritance
  • (D) All of these
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of these
Explanation: Common types of inheritance in Perl are:

Simple inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance