Home / Programming MCQs / Perl MCQs / Question

N

Nisha Gupta • 2.32K Points
Master

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

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.